views:

268

answers:

4

So I'm sending an HTTPWebRequest to a service and they are returning a userid in JSON.

They are returning: {"id: 123456"}

How do I process this? Should I just do a split on the " : " and take the second element or is there a proper way of doing this?

Thanks guys.

+3  A: 

You could do that, of course, but for anything more complex than that, I would strongly suggest you look at something like Json.NET to handle the deserialization for you.

mgroves
+6  A: 

you can do that or use a json serializer to deserialize it

if you are using .net 3.5 have a look at system.web.script.serialization.javascriptserializer

Yassir
A: 

The answer is in a previous post.

See link: http://stackoverflow.com/questions/423294/best-way-to-parse-json-data-into-a-asp-net-object

scptre
A: 

If you know the type of the object and you are using .net 3.5 you could add a Reference to System.ServiceModel.Web and serialize the object doing this:

var o = new DataContractJsonSerializer(
            typeof(YourClassHere)).ReadObject(Page.Request.InputStream);
VinTem