json格式字符串拼接

首先需引入命名空间using System.IO;using Newtonsoft.Json;

StringWriter stringWriter = new StringWriter();

using (JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter))
{

jsonWriter.WriteStartObject();

//一般key-value

jsonWriter.WritePropertyName("key");//key

jsonWriter.WriteValue(value);//value

//key-value([]数组)

jsonWriter.WritePropertyName("key");//key

jsonWriter.WriteStartArray();

jsonWriter.WriteValue(value);//value

jsonWriter.WriteEndArray();

//key-value({}对象)

jsonWriter.WritePropertyName("key");//key

jsonWriter.WriteStartObject();

jsonWriter.WritePropertyName("key1");//key

jsonWriter.WriteValue(value);//value

jsonWriter.WriteEndObject();

jsonWriter.WriteEndObject();

}

 

 

你可能感兴趣的:(.NET,C#)