Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Full "Loop" jSON Example?

Reply
Thread Tools

Full "Loop" jSON Example?

 
 
Alex Maghen
Guest
Posts: n/a
 
      05-22-2010
I am trying to do something which would seem so simple:

I have a simple Class in ASP.NET that I want to set up to be called and
consumed by a jQuery $.getjson() in a client-side JavaScript.

The Class I want to serialize to json as very simple (except that it has two
fields that are DateTime's and I've heard they're complicated).

I'd love a sample (if anyone has one) of the full code of the ASPX that
serializes and then delivers json (properly ContentType'd), AND a sample HTML
with the jQuery that $getjson()'s it and uses it.

I am having such a hard time with this and I just need a full sample to get
me going!

Many thanks.

Alex
 
Reply With Quote
 
 
 
 
Zhi-Qiang Ni[MSFT]
Guest
Posts: n/a
 
      05-24-2010
Hi Alex Maghen,

$.getJSON(url,data,callback)
Similar to $.post(), but expects the result to be JSON which is
automatically deserialized into a Javascript value and passed to the
callback as a parameter. While this function is handy for simple JSON
results there are two things to watch out for: Dates are not parsed since
there's no date literal in Javascript, so whatever the server returns will
be used (typically a string). $.getJSON() also doesn't support JSON POST
data - only POST encoded variables. This function is useful for simple JSON
results returned from arbitrary services, but not usable for calling WCF or
ASMX ASP.NET services since they expect JSON POST input.

If you have already use the WCF or ASMX service, I recommend that you use
the ASP.NET AJAX which support client side JSON serialization natively.
http://msdn.microsoft.com/en-us/library/bb924552.aspx
http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

However, if you insist on using only jQuery to call WCF, special handling
is required for deserialization.
Please refer to this article:
http://www.west-wind.com/presentatio...2.aspx#WCFASMX .

--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================

 
Reply With Quote
 
 
 
 
Alex Maghen
Guest
Posts: n/a
 
      05-24-2010
Thanks so much for the reply. Yes, I must use jQuery on the client-side (or
rather, I cannot assume that I can use anything from Microsoft because the
consumer of my json will not necessarily be under my control.

I've had a lot of success since I wrote you last, but I'm left with one more
problem: Any DateTime values that I serialize with "JavaScriptSerializer" are
output in a format the isn't parsed properly in jQuery. I can write a script
on the client side to clean this up, but I'd much rather have it created
cleanly in a way that is perfectly consumable and parseable in jQuery.
Everything else is workign fine, except for DateTime's. What can I do about
this?

Many thanks.

Alex

"Zhi-Qiang Ni[MSFT]" wrote:

> Hi Alex Maghen,
>
> $.getJSON(url,data,callback)
> Similar to $.post(), but expects the result to be JSON which is
> automatically deserialized into a Javascript value and passed to the
> callback as a parameter. While this function is handy for simple JSON
> results there are two things to watch out for: Dates are not parsed since
> there's no date literal in Javascript, so whatever the server returns will
> be used (typically a string). $.getJSON() also doesn't support JSON POST
> data - only POST encoded variables. This function is useful for simple JSON
> results returned from arbitrary services, but not usable for calling WCF or
> ASMX ASP.NET services since they expect JSON POST input.
>
> If you have already use the WCF or ASMX service, I recommend that you use
> the ASP.NET AJAX which support client side JSON serialization natively.
> http://msdn.microsoft.com/en-us/library/bb924552.aspx
> http://msdn.microsoft.com/en-us/magazine/cc163499.aspx
>
> However, if you insist on using only jQuery to call WCF, special handling
> is required for deserialization.
> Please refer to this article:
> http://www.west-wind.com/presentatio...2.aspx#WCFASMX .
>
> --
> Sincerely,
> Zhi-Qiang Ni
> Microsoft Online Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> MSDN Managed Newsgroup support offering is for non-urgent issues where an
> initial response from the community or a Microsoft Support Engineer within
> 2 business day is acceptable. Please note that each follow up response may
> take approximately 2 business days as the support professional working with
> you may need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations that require urgent,
> real-time or phone-based interactions. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
>
> .
>

 
Reply With Quote
 
Zhi-Qiang Ni[MSFT]
Guest
Posts: n/a
 
      05-26-2010
Hi Alex Maghen,

As my last reply, there is an article for deserializing the JSON from the
MS DateTime Format.
http://www.west-wind.com/presentatio...2.aspx#WCFASMX .

The related information of it ------------------
MS AJAX aware JavaScript JSON Serializer
jQuery does not include a JSON serializer. Since WCF/ASMX require
parameters to be sent as POST JSON objects, a serializer is required on the
client. The standard getJSON() deserialization also doesn¡¯t work with the
MS date format ("LastQuoteTime":"\/Date(1227578400000)\/") so special
handling is required for deserialization as well. For this task I¡¯ve
provided a modified version of Douglas Crockford¡¯s JSON2.js or
ww.jQuery.js both of which include JSON parsers that understand the
Microsoft date format both for serialization and deserialization.

This response contains a reference to a third party World Wide Web site.
Microsoft is providing this information as a convenience to you. Microsoft
does not control these sites and has not tested any software or information
found on these sites; therefore, Microsoft cannot make any representations
regarding the quality, safety, or suitability of any software or
information found there. There are inherent dangers in the use of any
software found on the Internet, and Microsoft cautions you to make sure
that you completely understand the risk before retrieving any software from
the Internet.

--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM
Options for generic full-text search without using database-specific full-text engine? Samuel R. Neff ASP .Net 2 06-10-2005 06:53 PM



Advertisments