如何设置和获取多个密钥对值 [英] How to set and get multiple key pair values
问题描述
我有以下格式的Json请求:
{
hardwareId:123-TEST-4567890,
输入:DeviceLocation,
请求:{
纬度:33.75,
经度: - 84.39,
海拔:0,
updateState:true,
eventDate:2016-02- 10T19:40:03.390Z
}
}
i我无法使用setter和getter for请求字段。如何在C#中设置和获取数组值。提前致谢
我尝试过:
我能够设置并获取hardwareId和Type fieds。我无法使用请求字段
这取决于您是否已从JSON创建obj1,或者您是否尝试从对象创建JSON你已经在C#中实例化了。
首先,你只需通过以下方式访问请求成员:
obj1 .request.latitude = 33.75;
obj1.request.longitude = - 84.39 // etc
第二种情况:
< pre lang =c#> obj1.request = new (){
latitude = 33.75,
经度= - 84.39 , // etc
};
obj1.hardwareid =ask-TEST-2;
obj1.type =DeviceLocation;
然后我如何处理请求?
我正在尝试从对象创建json
I have the Json request in following format:
{
"hardwareId": "123-TEST-4567890",
"type":"DeviceLocation",
"request": {
"latitude": "33.75",
"longitude": "-84.39",
"elevation": "0",
"updateState": true,
"eventDate": "2016-02-10T19:40:03.390Z"
}
}
i am unable to use the setters and getters for request field. How do i set and get array values in C#. Thanks in advance
What I have tried:
I am able to set and get hardwareId and Type fieds. I am unable to do so with the request field
This depends if you have created obj1 from the JSON, or if you are trying to create the JSON from an object you have instantiated in C#.
First case, you simply access the request members by:
obj1.request.latitude = "33.75"; obj1.request.longitude = "-84.39" // etc
Second case:
obj1.request = new () { latitude = "33.75", longitude = "-84.39", // etc };
obj1.hardwareid = "ask-TEST-2";
obj1.type = "DeviceLocation";
then how do i proceed with the request ?
i am trying to create the json from object
这篇关于如何设置和获取多个密钥对值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!