why do i let people talk me into using microsoft libraries to do ajax-related stuff? where's ruby when you need her?
have you had your starbucks?
Main Topics
Browse All Topicsif i have a plain-ol .net 2.0 proxy (client for rest-service) and that rest service returns JSON output, what's my best option to DESERIALIZE the json output back into an object?
said in ol-school church lady voice:
is it... AJAX.NET 2.0 Extensions 1.0...maybe?????!!!!
i don't want to have to load that entire library...or should i just parse it out myself?
or should i just load the damn library already (for my measly .net 2.0 client).
help me lord.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'm not sure exactly what you mean, but what the hay, if it's not helpful don't use it :)
When a JSON string is returned from a webservice, in many cases the result is automatically converted back into an object in JavaScript for example. I'm guessing you're talking about returning an object from a webservice in JSON format and then retaining the object structure as you use it in JavaScript? Not sure though you could be using the service in code behind?
Of course the object must be serializable, so if you're making the webservice yourself you have to bone up on that aspect. Most custom objects are or can be made serializable, but it can get tricky, usually its pretty academic (it just works).
So here's an example of a page that calls a webservice. The webservice creates a custom object and returns that as a JSON serialized string to the page. Then I use the OO structure on the returned object to populate it on the page...hope its of some help to you.
OR here's the same example with things a bit more manually done. In the WebService instead of returning an object type (which the framework handles for me) I am returning a JSON serialized string.
The return from the webservice method would look something like this (depending on what values are sent in):
{"a":"ddrfd","b":4}
This is returned to JavaScript and using the built in libraries I can manually convert it to an object. You can see how this is handled in the updated rMethod function.
>>>why do i let people talk me into using microsoft libraries to do ajax-related stuff?
>>Because they're super powerful once you get the hang of things :)
yes...but i meant vs. other ajax libraries. :) however i know that's a religious preference as there are tons of ajax frameworks & libraries out there (but a few solid main contenders).
ddayx10 - those are great examples; i do appreciate the time it took to pull them together as they are helpful (i.e. i know json parsed out in javascript is GENERALLY the way to go / generally how json is used in the field) but i have something a little different (and it's my fault for not expressing this more appropriately...i wuz just frustrated w/ my options).
BACKGROUND:
- i'm returning data from a service; List<myObj> ...serialized into a JSON string.
- MOST of my consumers of my 3.5 WCF REST-ful service want & use JSON in appropriate format (i.e. parse it out in javascript or bind to UI components using JQuery or AJAX /JS library approach).
so in these cases JSON is perfect, does its job...simple simple.
- i have ONE client for whom i'm to create a proxy obj. to call my RESTful service. they expect a DLL to be able to be installed on a website & pass response back to them, which they can in turn feed the end client/browser.
- it would be AWESOME (oh be it) that they would be able to accept json as output (in a string) from my proxy object...but they are asking for an actual object instead (i have to deserialize the JSON string into a typed object)
so i either build in XML as response type for that one consumer & handle separately OR if i can convince them json would be a simpler way to go to display data coming from the service...then that might be a good thing.
RESULTS FROM MY TESTING:
- i was able to extract out and create a JavaScriptSerializer.Deser
this worked BUT i must insert the TYPE of the object to make that method work...so still tightly coupled (would have to change my service & proxy, should myObj change)
and my proxy must be 2.0 --- if i had 3.5 framework as an option i could use DataContractJsonSerializer
in terms of answering my question, i guess JavaScriptSerializer.deser
thanks again for the input.
Sounds like you have a powerful understanding of this stuff already :)
Why is there always one who insists the world conforms to him? I mean JS/XML whatever you choose are used precisely to overcome these types of issues! To send them an object is going to require some intermediary... ah well they must be good consumers or you'd not be putting up with this I suppose.
Wish I had any suggestions for you. I think you're best bet is a sales job on your client in getting them to accept JSON or XML. I don't see how you can send an "object"?!
PS: the code samples I did were extremely basic and required very little effort, no worries :)
this one was tricky: i needed to provide a SERIALIZE method on an object in a client-side proxy. the object gets created by the proxy by making a call to a REST service. and only .NET 2.0 available on the machine running the client-side proxy.
TWO ANSWERS i found to this solution:
1) as mentioned above I extracted out the necessary portion of JsonDeserialize from AJAX 2.0 Extensions 1.0...which deserialized JSON output from REST service *into* an object for my .net 2.0 class library to use to feed the object to my client (the client consumes the class library and I call the rest service to get them their object).
BUT - then tightly coupled with the client and it's not a very flexible design either, should my object change. AND - i'm not sure microsoft is cool with me pulling out just the stuff i needed from their AJAX library...at least not without tons of disclaimers or something.
...and i have to have a shared class library with my MyServerObjType in it.
2) the solution i went with: i added a web service interface (regular ol' WCF web service on server side), returned XML as output. this gets automatically deserialized by the client-side proxy which of course gets auto-generated as you add a reference to your service (STEP 1)
then i found that attempting to include the ToXml and use [Serialize] inside the DataContract which I was returning would cause the compiler to choke...since that DataContract itself gets serialized & deserialized on the server side, with the ToXml method never showing up on the client after deserialization into an object.
(STEP 2 - workaround) i wound up putting a ToXml method inside a helper class alongside the client proxy...so now i can do HelperClass.GetXml(typeof(
this is more flexible as i don't have to use the json deserialization method from microsoft...and if my object changes server-side i just regenerate my serviceProxy...eliminating
thanks to ddayx10 for the responses...if i simply had the browser as my client (instead of a .NET class library as a proxy) i could've use dday's code which is a nice example of how to deserialize using javascript. i had to deserialize using C#, as my class library is consumed by another C# object, not a browser.
hope the above makes sense...and maybe my explanation can be simplified...but it's early. :)
Business Accounts
Answer for Membership
by: nespaPosted on 2009-08-28 at 08:55:57ID: 25208951
...and i won't be lazy about this...i'll download the source for the library right now...while yer having your starbucks trying to decide if you should bother to answer this.
can i just steal it & put in my code or do i have to sign in blood to microsoft that they are the ultimate?
why is there air?
i'll report back shortly... thanks.