开发者

Processing JSON response in an ASP.NET webform

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 开发者_如何学JAVAdoing this?


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


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜