// See https://aka.ms/new-console-template for more information
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrBit.MESInterface.OrderVerifyWebService.Application;
string aaa = "{\r\n \"Code\": 200,\r\n \"Data\": [\r\n {\r\n \"ID\": \"1002311180000366\",\r\n \"DocNo\": \"HBRC231100035\"\r\n }\r\n ],\r\n \"Msg\": \"\"\r\n}";
AnalyticResult analyticResult = new AnalyticResult();
var jobj = DeserializeStringToObject(aaa);
analyticResult.data = jobj;
var jstr = JsonConvert.SerializeObject(analyticResult);
Console.WriteLine(jstr);
///
/// 将json字符串反序列化为字典类型
///
/// 字典key
/// 字典value
/// json字符串
/// 字典数据
static Dictionary DeserializeStringToDictionary(string jsonStr)
{
if (string.IsNullOrEmpty(jsonStr))
return new Dictionary();
Dictionary jsonDict = JsonConvert.DeserializeObject>(jsonStr);
return jsonDict;
}
///
/// 根据json字符串类型将json字符串反序列化为字典或者集合类型
///
///
///
static object DeserializeStringToObject(string jsonStr)
{
if (isJArray(jsonStr))
{
return JsonConvert.DeserializeObject>>(jsonStr);
}
return DeserializeStringToDictionary(jsonStr);
}
static bool isJArray(string json)
{
if (string.IsNullOrEmpty(json))
{
return false;
}
try
{
JArray.Parse(json);
return true;
}
catch
{
return false;
}
}