C# 遍历 Json 数组, .net core 如何遍历 json 数组
using Newtonsoft.Json.Linq;
using System;
using System.Text;
namespace ConsoleApp41
{
internal class Program
{
static void Main(string[] args)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("{");
builder.AppendLine("\"key1\":\"value1\",");
builder.AppendLine("\"key2\":\"value2\",");
builder.AppendLine("\"key3\":\"value3\",");
builder.AppendLine("}");
JObject jObject = JObject.Parse(builder.ToString());
foreach (JProperty property in jObject.Properties())
{
Console.WriteLine("key:" + property.Name + " value:" + property.Value);
}
Console.ReadKey();
}
}
}