1.写入Json中{“detailList”:[],“Type”:“zed”}。向此Json文件中detailList累次插入内容
JObject jobject;
JObject newStu;
private void AddDataToJson(string[] Data)
{
newStu = new JObject(
new JProperty(“字段”, “值”),
new JProperty(“字段”, Data[0]),
new JProperty(“字段”, Data[1]),
new JProperty(“字段”, Data[2]),
new JProperty(“字段”, “60”),
new JProperty(“字段”, Data[3]),
new JProperty(“字段”, Data[4]),
new JProperty(“字段”, “123213”),
new JProperty(“字段”, “0”),
new JProperty(“字段”, “0”),
new JProperty(“字段”, Data[5]),
new JProperty(“字段”, Data[6])
);
jobject[“detailList”].Last.AddAfterSelf(newStu);
}
2.读取Json文件
{
“payload”: {
“id”: “1”,
“name”: “1”,
“appTag”: “1”,
“description”: null,
“secret”: “0”,
“url”: null,
“appLogo”: null,
“status”: true,
“access”: “1”
},
“code”: 0,
“msg”: “ok”
}
Json文件如上
internal struct ValueGet
{
public payload payload;
public string code { get; set; }
public string msg { get; set; }
}
internal struct payload
{
public string id { get; set; }
public string name { get; set; }
public string appTag { get; set; }
public string description { get; set; }
public string secret { get; set; }
public string url { get; set; }
public string appLogo { get; set; }
public bool status { get; set; }
public string accessToken { get; set; }
}
调用:
string result=“{ …}” //Json文件
ValueGet rt = JsonConvert.DeserializeObject(result);
string ResultValue=rt.payload.name;