mql4 - 在 mql4 中处理 json 字符串
问题描述
我收到了以下字符串:
{"records":[{"id":"rec4haaOncoQniu8U","fields":{"orders1":5},"createdTime":"2020-02-08T09:08:22.000Z"}]}
我不明白如何使用位于此处的“JAson.mqh”库处理和分离 mql4 中 json 的值:https ://www.mql5.com/en/code/13663
我需要位于 "fields" 下的 "orders" 的值,value = 5。唯一改变的“键”是“字段”值中的键。
我希望能够通过以下方式获取值:
string value1 = Result[0].["fields"].["orders1"]; //5
string value2 = Result[0].["fields"].["orders2"];
请让我知道我能做什么。
解决方案
您可以使用以下格式获取值。请注意,它必须强制转换为类型。(我已将其转换int
为 中的类型JSON
,但您也可以将其转换string
为)
int value1 = json["records"][0]["fields"]["orders1"].ToInt(); // if you want to make it a string use ToStr() instead of ToInt()
这是我所做的完整示例
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());
希望它有所帮助。
推荐阅读
- javascript - 网页加载时出现javascript错误“未选择项目”
- flutter - 否则颤振
- sql - 地理点范围和数值范围查询的复合多列索引
- odoo - Odoo如何显示详细信息表并在每个单元格中从many2one字段中选择一个选项?
- python - aws lambda python ImportError:python中没有语言'eng'的本地化支持
- c# - 在后面的代码中设置两个属性之间的绑定
- python - CVXPY - 如何在没有解析表达式的情况下解决优化问题
- python - 对python有限制的排列
- python - 如何在一个客户端断开连接后让 python 套接字监听?
- c++ - istream std::cin 如何修改自定义 istream 缓冲区?