views:

34

answers:

2

In my ASP.NET MVC project I am conecting to a remote cloud server which is returning the data in json like:

[{
    "name":"new-service-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?

+3  A: 

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();
    }
Simon Steele
+1 you can read more here, http://james.newtonking.com/pages/json-net.aspx
dove
A: 

asp.net has an extension dll called system.web.extensions which is having support for javascript and json serialization. see this link

lakhlaniprashant.blogspot.com