从 C# 中的 (dynamic)json 访问对象 json.`params`(保留关键字)
accessing object json.`params` (reserved keyword) from (dynamic)json in c#
我正在调用一个 api,其中 returns 一些 json。
收到的json格式如下:
{
"method": "depth.update",
"params": [
true,
{
"asks": [
[
"8000.00",
"9.6250"
]
],
"bids": [
[
"8000.00",
"9.6250"
]
]
},
"EOS_USDT"
],
"id": null
}
注意对象 params
中的询价和出价,我正在尝试访问它。
json 正在反序列化为动态。
如下例所示,我可以通过调用 json.method
来访问对象。
// retrieve response
string message = Receivestring();
// deserialize
dynamic json = JsonConvert.DeserializeObject<dynamic>(message);
// check if we are in the correct method
if (json.method == "depth.update")
{
// -> this does not work <--
dynamic parameters = json.params;
}
else if (json.method == "other.method")
{
dynamic success = json.result;
}
问题:
json.params
将不起作用。我猜这是一个保留关键字,Visual Studio 尝试匹配。
那我怎样才能访问json.params
?
因为params
是c#的关键字,可以尝试用@
转义keyword
json.@params
我正在调用一个 api,其中 returns 一些 json。 收到的json格式如下:
{
"method": "depth.update",
"params": [
true,
{
"asks": [
[
"8000.00",
"9.6250"
]
],
"bids": [
[
"8000.00",
"9.6250"
]
]
},
"EOS_USDT"
],
"id": null
}
注意对象 params
中的询价和出价,我正在尝试访问它。
json 正在反序列化为动态。
如下例所示,我可以通过调用 json.method
来访问对象。
// retrieve response
string message = Receivestring();
// deserialize
dynamic json = JsonConvert.DeserializeObject<dynamic>(message);
// check if we are in the correct method
if (json.method == "depth.update")
{
// -> this does not work <--
dynamic parameters = json.params;
}
else if (json.method == "other.method")
{
dynamic success = json.result;
}
问题:
json.params
将不起作用。我猜这是一个保留关键字,Visual Studio 尝试匹配。
那我怎样才能访问json.params
?
因为params
是c#的关键字,可以尝试用@
转义keyword
json.@params