如何读取JSON文件格式,以及如何编写在c#asp.net的JSON [英] How to read json file format and how to write the json in c# asp.net

查看:435
本文介绍了如何读取JSON文件格式,以及如何编写在c#asp.net的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC项目我conecting到在JSON返回数据的远程云服务器,如:

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"
}]

现在我想在列表或阵列格式所有的值,比如我想获得cdn_uri

Now I want to get all the values in list or array format, for example I want to get "cdn_uri".

我也想在我的code某处创建JSON,我该如何创建并写入JSON?

I also want to create JSON somewhere in my code, how do I create and write JSON?

推荐答案

您可以从codePLEX使用JSON.Net组件:

You can use the JSON.Net component from codeplex:

HTTP://json.$c$cplex.com/

这将让你读/写JSON。下面是使用JSON你从问题一个简单的例子:

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();
    }

这篇关于如何读取JSON文件格式,以及如何编写在c#asp.net的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆