In my ASP.NET MVC project I am conecting to a remote cloud server which is returning the data in json like:
[{
"name":"new-se开发者_C百科rvice-dev",
"Isenabled":"true",
"ttl":86400,
"cdn_uri":"http://c0099.cdn2.files.rackspacecloud.com",
"referrer_acl":"",
"useragent_acl":"",
"log_":"false"
}]
Now I want to get all the values in list or array format, for example I want to get "cdn_uri"
.
I also want to create JSON somewhere in my code, how do I create and write JSON?
You can use the JSON.Net component from codeplex:
http://json.codeplex.com/
This will let you read/write JSON. Here's a simple example using your JSON from the question:
static void Main(string[] args)
{
JObject o =
JObject.Parse(
"{ \"name\":\"new-service-dev\", \"Isenabled\":\"true\", \"ttl\":86400, \"cdn_uri\":\"http://c0099.cdn2.files.rackspacecloud.com\", \"referrer_acl\":\"\", \"useragent_acl\":\"\", \"log_\":\"false\"}");
string cdn_uri = (string)o.SelectToken("cdn_uri");
Console.WriteLine(cdn_uri);
Console.ReadKey();
}
asp.net has an extension dll called system.web.extensions which is having support for javascript and json serialization. see this link
精彩评论