本文介绍了如何在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"]]}
推荐答案
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; }
}
}
这篇关于如何在c#中创建json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!