2

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?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117

3 Answers3

8

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

Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
4

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.

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
0

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);
Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
thitemple
  • 5,833
  • 4
  • 42
  • 67