異なるフィールドが返されるため、下のJSONスニペットをdeserialzerに苦労しています。例えば、configの場合、これはconfig.onで正常に動作します。これはconfigブロックにありますが、違う、どうやってこれを丸めるの? JSONは、異なるフィールドに接続されたすべての異なるセンサーを返します。JSONを逆シリアル化する
dynamic obj = JsonConvert.DeserializeObject(response);
//
foreach (var item in obj)
{
string temperature = item.ToString(); //this shows the full object in text
// Debug.WriteLine(temperature); //this shows the full object in text
dynamic group = item;
string idstring = group.Name.ToString();
foreach (var prop in group)
{
string name = prop.name;
string temp = prop.config.on;
//string temp = prop.state.lastupdated;
//string temp = prop.swversion;
//Debug.WriteLine(temp);
string namestring = name.ToString();
string tempstring = temp.ToString();
arr[0] = idstring.ToLower();
arr[1] = namestring.ToLower();
arr[2] = tempstring.ToLower();
JSONレスポンス
{
"1": {
"state": {
"daylight": true,
"lastupdated": "2017-03-10T07:01:00"
},
"config": {
"on": true,
"configured": true,
"sunriseoffset": 30,
"sunsetoffset": -30
},
"name": "Daylight",
"type": "Daylight",
"modelid": "PHDL00",
"manufacturername": "Philips",
"swversion": "1.0"
},
"2": {
"state": {
"temperature": 1830,
"lastupdated": "2017-03-10T08:11:51"
},
"config": {
"on": true,
"battery": 100,
"reachable": true,
"alert": "none",
"ledindication": false,
"usertest": false,
"pending": [
},
"name": "Hall",
"type": "ZLLPresence",
"modelid": "SML001",
"manufacturername": "Philips",
"swversion": "6.1.0.18912",
"uniqueid": "00:17:88:01:02:01:8b:be-02-0406"
},
"4": {
"state": {
"lightlevel": 12270,
"dark": true,
"daylight": false,
"lastupdated": "2017-03-10T08:14:28"
},
"config": {
"on": true,
"battery": 100,
"reachable": true,
"alert": "none",
"tholddark": 16011,
"tholdoffset": 7000,
"ledindication": false,
"usertest": false,
"pending": [
]
},
"name": "Hue ambient light sensor 1",
"type": "ZLLLightLevel",
"modelid": "SML001",
"manufacturername": "Philips",
"swversion": "6.1.0.18912",
"uniqueid": "00:17:88:01:02:01:8b:be-02-0400"
},
"5": {
"state": {
"temperature": 1919,
"lastupdated": "2017-03-10T08:12:50"
を - あなたはこのC#]をタグ付けすることを意味しましたか? – UnholySheep
はいいいえC# – Andy