Reading JSON in ASP.NET
I have the newtonsoft library. I want to re开发者_开发知识库ad email id
and name
from the following JSON string:
var InitialContacts =
[
{"guid":"","contactId":"32","contactName":"a, a a","email":"net.hitesh@gmail.com","isConnection":false,"connection":"","displayImg":null,"msgrID":"","msgrStatus":"","isMsgrBuddy":false},
{"guid":"","contactId":"26","contactName":"bhaiya, manish","email":"yadavmanish_27@yahoo.co.in","isConnection":false,"connection":"","displayImg":null,"msgrID":"","msgrStatus":"","isMsgrBuddy":false}
]
How can I read it in ASP.NET?
Two solutions:
With JSON.Net you can create a class that matches the elements of the JSON string. In this case (Note - this is air code, haven't tested it):
public class TargetClass
{
public string guid{get; set;}
public int contactId{get; set;}
...
}
You can deserialize to a List.
Another way is to use the delimiters , & : and split the string into an array first by ",". Then for each entry in the array, split again with the ":".
精彩评论