C#使用Json.Net遍历Json

StringBuilder builder=new StringBuilder();
builder.AppendLine("{");
builder.AppendLine("\"key1\":\"value1\",");
builder.AppendLine("\"key2\":\"value2\",");
builder.AppendLine("\"key3\":\"value3\",");
builder.AppendLine("\"key4\":\"value4\",");
builder.AppendLine("\"key5\":\"value5\",");
builder.AppendLine("\"key6\":\"value6\"");
builder.AppendLine("}");
JObject jObject=JObject.Parse(builder.ToString());
foreach (JProperty jProperty in jObject.Properties())
{
   Console.WriteLine("key:"+jProperty.Name+" value:"+jProperty.Value);
}
Console.ReadKey();

  

posted @ 2019-05-22 14:17  86727515  阅读(3084)  评论(0编辑  收藏  举报