Nat*_*lan 7 c# serialization json
我如何在没有 C# 类的情况下解析这个 json。我不知道该使用数组还是其他任何东西。
这是我想要解析的json结果
{
"success": true,
"status": 200,
"message": "SUCCESS",
"response": {
"message": "Device Registered",
"data": [
{
"ID": "607dbb9e08b4c22a",
"Type_ID": "657911C6-AFA5-4AC4-922F-39E56CCB28CC",
"Name": "Genymotion Google Nexus 5X",
"Active": "1",
"Insert_User": "Default",
"Insert_Date": "2019-10-18 16:33:01.650",
"Update_User": "Default",
"Update_Date": "2019-10-18 16:33:01.650"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家,我只是自己弄清楚。这就是我所做的。
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public async Task<string> CheckDevice(string id)
{
var uri = new Uri(string.Format(Constant.CheckDevicesRegistration + "id=" + id, string.Empty));
try
{
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
var jsonData = (JObject)JsonConvert.DeserializeObject(result);
var message = jsonData["response"]["message"].Value<string>();
resultService = message;
}
}
catch
{
resultService = "Connection-Error";
}
return resultService;
}
Run Code Online (Sandbox Code Playgroud)