在c#中从字典中获取值
本文关键字:获取 字典 | 更新日期: 2023-09-27 18:12:58
我正在尝试从c#字典中获取街道,但它不工作(得到一些错误)
代码string data_scope_api = '[
{
"retailerName": "vv",
"name": null,
"address": {
"fullShopName": "vv",
"street": "vv",
},
},
{
"retailerName": "vv",
"name": null,
"address": {
"fullShopName": "vv",
"street": "vv"
},
}
]'
dynamic results = JsonConvert.DeserializeObject<dynamic>(data_scope_api);
foreach (var result in results) {
string address = result.address;
Console.Write (address);
foreach (var address_1 in address) {
string store_street = address_1.street;
Console.Write (store_street);
}
}
误差Program.cs(37,37): Error CS1061: Type `char' does not contain a definition for `street' and no extension method `street' of type `char' could be found. Are you missing an assembly reference? (CS1061) (test)
如何修复并使这个程序工作?
您将地址转换为字符串变量。
foreach (var result in results)
{
dynamic address = result.address; // address is dynamic address json
Console.Write(address);
string store_street = address.street; // street is string data
Console.Write(store_street);
}