如何使用从 API 收到的 JSON 格式的数据?
How do I use data I receive from API in JSON format?
在我调用 API(获取)后,我收到了这个答复:
"medios": [
{
"id": "2",
"name": "Banco Galicia",
"type": "a",
"img": "/method/21030342",
"medios_id": "0"
},
{
"id": "3",
"name": "Bango River",
"type": "Banco",
"img": "/method/210321012",
"medios_id": "0"
}
]
我有我的 "get / set" class:
public class Medio
{
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string img { get; set; }
public string medios_id { get; set; }
}
我的问题是:我如何让它们一起工作...意思是:使用我从 api 收到的 ID 来获取 ID,等等?
谢谢!
只需使用 NuGet 的 NewtonSoft.Json 包将 json 转换为您的 class 类型列表
List<Medio> list = JsonConvert.DeserializeObject<List<Medio>>(your_string)
尝试如下:-
var yourObj = JsonConvert.DeserializeObject<List<Medio>>(json);
在我调用 API(获取)后,我收到了这个答复:
"medios": [
{
"id": "2",
"name": "Banco Galicia",
"type": "a",
"img": "/method/21030342",
"medios_id": "0"
},
{
"id": "3",
"name": "Bango River",
"type": "Banco",
"img": "/method/210321012",
"medios_id": "0"
}
]
我有我的 "get / set" class:
public class Medio
{
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string img { get; set; }
public string medios_id { get; set; }
}
我的问题是:我如何让它们一起工作...意思是:使用我从 api 收到的 ID 来获取 ID,等等?
谢谢!
只需使用 NuGet 的 NewtonSoft.Json 包将 json 转换为您的 class 类型列表
List<Medio> list = JsonConvert.DeserializeObject<List<Medio>>(your_string)
尝试如下:-
var yourObj = JsonConvert.DeserializeObject<List<Medio>>(json);