我有这个JSON结果,我从API收到有一个简单的方法来获取所需的值从响应?只需要将这些值AssetName、SystemID、Lat、Lng和Timestmp放入名为Result的自定义类中
结果Json如下所示
{
"result": [
{
"Asset": {
"AssetName": "Banner",
"AssetType": "Medic",
"AssetCategory": "Personnel",
"Hardware": {
"HardwareName": " Tag 88",
"HardwareType": "Personnel Tag",
"HardwareFamily": " Group 2",
"DeviceType": "Location Tag",
"SystemId": "8845"
}
},
"DetectingAsset": {
"AssetName": "Shop 2 TR",
"AssetType": "Tag Reader",
"AssetCategory": "Network Access Point",
"Hardware": {
"HardwareName": "2 TR",
"HardwareType": "Tag Reader",
"HardwareFamily": "Group 2",
"DeviceType": "Tag Reader",
"SystemId": "9.9.1"
}
},
"Location": {
"Maps": [
"Hard Rock"
],
"Zone": "Machine Shop",
"Lat": null,
"Lng": null
},
"Timestamp": "2023-05-05T11:07:45.673"
},
{
"Asset": {
"AssetName": "Test1",
"AssetType": "Medic",
"AssetCategory": "Personnel",
"Hardware": {
"HardwareName": "Tag 88",
"HardwareType": "Personnel Tag",
"HardwareFamily": "Group ABIP",
"DeviceType": "Location Tag",
"SystemId": "1022"
}
},
"DetectingAsset": {
"AssetName": "Machine Shop 2 TR",
"AssetType": "Tag Reader",
"AssetCategory": "Network Access Point",
"Hardware": {
"HardwareName": "2 TR",
"HardwareType": "Tag Reader",
"HardwareFamily": "Group AIP",
"DeviceType": "Tag Reader",
"SystemId": "9.9.1"
}
},
"Location": {
"Maps": [
"Hard Rock"
],
"Zone": "Machine Shop",
"Lat": null,
"Lng": null
},
"Timestamp": "2023-05-05T11:07:45.673"
}
]
}
我创建的类如下
class Result
{
public APIResult[] aPIResult { get; set; }
}
class Result
{
public string TimeStamp { get; set; }
public string AssetName { get; set; }
public string locationLat { get; set; }
public string locationLng { get; set; }
public string SystemId {get;set;}
}
4条答案
按热度按时间bmvo0sr51#
您可以使用
Newtonsoft.Json
(Json.NET)库中的JObject
类来解析并从JSON响应中提取所需的值。0kjbasz62#
可以使用Newtonsoft.Json.JsonConvert
ycggw6v23#
您可以使用System.Text.Json来实现此功能(可通过Visual Studio中的Nuget Package Manager安装):
jdgnovmf4#
你可以试试这个代码