开发者

How to read json file format and how to write the json in c# asp.net

开发者 https://www.devze.com 2023-01-20 15:41 出处:网络
In my ASP.NET MVC project I am conecting to a remote cloud server which is returning the data in json like:

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

0

精彩评论

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

关注公众号