如何在c#中创建json [英] how to create json in c#

查看:117
本文介绍了如何在c#中创建json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中创建这样的json字符串:



{aaData:[

[Trident, Internet Explorer 4.0,Win 95 +,4,X],

[Trident,Internet Explorer 5.0,Win 95 +,5, C],

[Trident,Internet Explorer 5.5,Win 95 +,5.5,A]]}

How to create a json string like this in C#:

{ "aaData": [
["Trident","Internet Explorer 4.0","Win 95+","4","X"],
["Trident","Internet Explorer 5.0","Win 95+","5","C"],
["Trident","Internet Explorer 5.5","Win 95+","5.5","A"]]}

推荐答案

你可以试试Json.Net。示例控制台应用程序代码:



you can try with Json.Net. Sample console application code:

using System.Collections.Generic;
using Newtonsoft.Json;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            MyData data = new MyData()
            {
                aaData = new List<list><string>>()
                { 
                    new List<string>(){"Trident","Internet Explorer 4.0","Win 95+","4","X"},
                    new List<string>(){"Trident","Internet Explorer 5.0","Win 95+","5","C"},
                    new List<string>(){"Trident","Internet Explorer 5.5","Win 95+","5.5","A"}}
                };

            string json = JsonConvert.SerializeObject(data);

            //{"aaData":[["Trident","Internet Explorer 4.0","Win 95+","4","X"],["Trident","Internet Explorer 5.0","Win 95+","5","C"],["Trident","Internet Explorer 5.5","Win 95+","5.5","A"]]}

        }
    }

    public class MyData
    {
        public List<list><string>> aaData { get; set; }
    }
}


参考以下链接:



Create-JSON-from-C-using-JSON-Library

如何创建-json-string-in-c-sharp



希望有所帮助:)
Take reference from the below links:

Create-JSON-from-C-using-JSON-Library
how-to-create-json-string-in-c-sharp

Hope it helps :)


使用 String.Format 方法,或 StringBuilder 对象。


这篇关于如何在c#中创建json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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