我試圖反序列化JSON字符串中JObject機智Newtosoft.Json Raspbian下單聲道。但它無法反序列化Float。Newtonsoft.JSON單浮動反序列化異常
Dim myStationJSON As String
myStationJSON = myWC.DownloadString("https://api.netatmo.com/api/getstationsdata?access_token=" & myToken.Token.access_token)
Dim myJSON As Newtonsoft.Json.Linq.JObject
Dim myStationName As String = ""
Dim opts As New Newtonsoft.Json.JsonSerializerSettings
opts.FloatParseHandling = Newtonsoft.Json.FloatParseHandling.Double
myJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(myStationJSON, opts)
我得到這個異常:
Newtonsoft.Json.JsonReaderException:輸入字符串 '-0.2' 不是一個有效的數字。路徑 'body.devices [0] .modules [0] .dashboard_data.Temperature',第1行,位置329 在Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)[0x00000]在:0 在Newtonsoft.Json。在Newtonsoft.JsonTextReader.Read()[0x00000]中:0 在Newtonsoft.Json.JsonWriter.WriteToken(Newtonsoft.Json.JsonReader reader,Boolean writeChildren,Boolean writeDateConstructorAsDate()[0x00000] in:0 at Newtonsoft.Json.JsonTextReader.Read ,布爾writeComments)[0x00000]中:0 at Newtonsoft.Json。 Serialization.JsonSerializerInternalReader.CreateJObject(Newtonsoft.Json.JsonReader讀取器)[0x00000]在:0 在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(Newtonsoft.Json.JsonReader讀卡器,System.Type的的objectType,Newtonsoft.Json.Serialization.JsonContract合同,Newtonsoft.Json.Serialization.JsonProperty構件,Newtonsoft.Json.Serialization.JsonContainerContract containerContract ,Newtonsoft.Json.Serialization.JsonProperty containerMember,System.Object existingValue)[0x00000] in:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(Newtonsoft.Json.JsonReader reader,System.Type objectType,Newtonsoft.Json.Serialization .JsonContract合同,Newtonsoft.Json.Serialization.JsonProperty成員,Newtonsoft.Json.Serialization.JsonContainerContract containerContract,Newtonsoft.Json.Serialization.JsonProperty containerMember,System.Object existingValue)[0x00000]中的:0 at Newtonsoft.Json.Serialization。 JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.Js onReader讀者的System.Type的objectType,布爾checkAdditionalContent)[0x00000]中:0
JSON:
{
"body": {
"devices": [
{
"_id": "XXX",
"cipher_id": "enc:16:XXX",
"last_status_store": 1483489982,
"modules": [
{
"_id": "XXX",
"type": "NAModule1",
"last_message": 1483489978,
"last_seen": 1483489933,
"dashboard_data": {
"time_utc": 1483489933,
"Temperature": -0.2,
"temp_trend": "stable",
"Humidity": 89,
"date_max_temp": 1483489933,
"date_min_temp": 1483484498,
"min_temp": -0.4,
"max_temp": -0.2
},
"data_type": [
"Temperature",
"Humidity"
],
"module_name": "Außen",
"last_setup": 1384606905,
"battery_vp": 5870,
"battery_percent": 95,
"rf_status": 81,
"firmware": 43
},
{
"_id": "XXXX",
"type": "NAModule4",
"last_message": 1483489978,
"last_seen": 1483489933,
"dashboard_data": {
"time_utc": 1483489933,
"Temperature": 21.7,
"temp_trend": "stable",
"Humidity": 38,
"CO2": 1139,
"date_max_temp": 1483489933,
"date_min_temp": 1483485422,
"min_temp": 21.5,
"max_temp": 21.7
},
"data_type": [
"Temperature",
"CO2",
"Humidity"
],
"module_name": "Schlafzimmer",
"last_setup": 1414704430,
"battery_vp": 4876,
"battery_percent": 38,
"rf_status": 79,
"firmware": 43
}
],
"place": {
"altitude": 210,
"city": "XXX",
"country": "DE",
"timezone": "Europe/XXX",
"location": [
3.12345675665,
12.12345667899
]
},
"station_name": "XXX",
"type": "NAMain",
"dashboard_data": {
"AbsolutePressure": 993.7,
"time_utc": 1483489969,
"Noise": 51,
"Temperature": 21.8,
"temp_trend": "stable",
"Humidity": 44,
"Pressure": 1021.2,
"pressure_trend": "down",
"CO2": 1069,
"date_max_temp": 1483484530,
"date_min_temp": 1483485740,
"min_temp": 21.6,
"max_temp": 21.8
},
"data_type": [
"Temperature",
"CO2",
"Humidity",
"Noise",
"Pressure"
],
"co2_calibrating": false,
"date_setup": 1384607020,
"last_setup": 1384607020,
"module_name": "Wohnzimmer",
"firmware": 102,
"last_upgrade": 1440006125,
"wifi_status": 62,
"friend_users": [
"XXXX"
]
}
],
"user": {
"mail": "[email protected]",
"administrative": {
"country": "DE",
"reg_locale": "de-DE",
"lang": "de-DE",
"unit": 0,
"windunit": 0,
"pressureunit": 0,
"feel_like_algo": 0
}
}
},
"status": "ok",
"time_exec": 0.050105810165405,
"time_server": 1483490016
}
在Windows中它工作得很好。
你能[編輯]你的問題,包括有問題的JSON,使我們有充分的[MCVE]? – dbc
剛剛添加了JSON。 – TimeO84