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
  • 95,348
  • 63
  • 249
  • 319
Jack Marchetti
  • 15,254
  • 13
  • 78
  • 116

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
  • 19,642
  • 23
  • 75
  • 111
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
  • 24,204
  • 9
  • 72
  • 117
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
  • 19,642
  • 23
  • 75
  • 111
thitemple
  • 5,643
  • 3
  • 41
  • 63