using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
namespace JsonTest
{
class Program
{
static void Main(string[] args)
{
string str = "{\"code\":123,\"msg\":\"err...\"}";
JObject jobject = JObject.Parse(str);
if (jobject.Property("code") == null || jobject.Property("code").ToString() == "")
{
Console.WriteLine("键值key不存在!");
}
//或者
bool hasCode = jobject.Properties().Any(p => p.Name == "code")
//bool hasCode = (jobject.Property("code") != null);
IEnumerable<JProperty> properties = jobject.Properties();
foreach (JProperty item in properties)
{
Console.WriteLine(item.Name + ":" + item.Value);
}
Console.ReadKey();
}
}
}
11-18
4154
