问题描述
我收到了以下字符串:
{"records":[{"id":"rec4haaOncoQniu8U","fields":{"orders1":5},"createdTime":"2020-02-08T09:08:22.000Z"}]}
我不了解如何使用位于以下位置的"JAson.mqh"库在mql4中处理和分离json的值: https://www.mql5.com/zh-CN/code/13663
I am not understanding how I can process and separate the values of the json in mql4 using the "JAson.mqh " library, located here: https://www.mql5.com/en/code/13663
我需要位于字段"下的订单"值,值= 5 .唯一更改的键"是字段"值内的键.
I need the values of "orders" located under "fields" , value = 5.the only "KEYS" that changes are the keys within the "fields" values.
我希望能够通过以下方式获取值:
i would like to be able to get the values with something like this:
string value1 = Result[0].["fields"].["orders1"]; //5
string value2 = Result[0].["fields"].["orders2"];
请让我知道我能做什么.
Please let me know what I can do.
推荐答案
您可以使用以下格式获取值.请注意,必须将其强制转换为类型. (我将其强制转换为int
,因为它是JSON
中的类型,但是您也可以将其强制转换为string
)
You can get the value using the following format. Note that it has to be casted to a type. (I have casted it to int
as it is the type it is in the JSON
, but you can cast it to string
as well)
int value1 = json["records"][0]["fields"]["orders1"].ToInt(); // if you want to make it a string use ToStr() instead of ToInt()
这是我所做的事情的完整例子
Here is a full example of what I did
string jsonString = "{\"records\": [{\"id\": \"rec4haaOncoQniu8U\",\"fields\": {\"orders1\": 5 }\"createdTime\": \"2020-02-08T09:08:22.000Z\"}]}";
if(json.Deserialize(jsonString))
Alert(json["records"][0]["fields"]["orders1"].ToInt());
希望有帮助.
这篇关于在mql4中处理json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!