Я использую Arduino и Open Weather Map API, чтобы создать метеорологическую станцию, но у меня возникли серьезные проблемы с анализом ответа на что-то полезное с помощью sscanf.sscanf с двойными кавычками
Вот пример один ответ:
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"cmc stations","main":{"temp":14.17,"pressure":1012,"humidity":74,"temp_min":13,"temp_max":15.8},"wind":{"speed":4.6,"deg":150},"clouds":{"all":0},"dt":1459602835,"sys":{"type":1,"id":5091,"message":0.0059,"country":"GB","sunrise":1459575095,"sunset":1459622222},"id":2643743,"name":"London","cod":200}
Я хотел бы разобрать информацию о погоде (Clear) от:
"weather":[{"id":800,"main":"Clear",
, и информация Темп (14) от:
"main":{"temp":14.17,
Это код, который я использую:
if (character == '}') { // Just a delimiter
if (strstr(response, "\"weather\":[{")) { // to confirm that the string was found
sscanf(response, ",main\":%s,", weather);
Serial.printfn("\r\nfound weather = %s"), weather;
}
else if (strstr(response, "\"main\":{\"temp\":")) { // to confirm that the string was found
sscanf(response, "temp\":%2s,", temp);
Serial.printfn("\r\nfound temp = %s"), temp;
}
memset(response, 0, sizeof(response));
idx = 0;
}
Но sscanf seens даже не работает, так как он всегда печатает целые строки продолжительностью 32 байт.
found weather = ,"weather":[{"id":800,"main":"Clear","description":
found temp = ],"base":"cmc stations","main":{"temp":14.17,"pressure":1011,"humi
У любого есть ключ к анализу этих строк с помощью sscanf?
Используйте '% [^ \ "] ', чтобы указать " пока я не прочитал '\" '" – Maikel
У вас есть 'sscanf_s' имеющийся? Или существует Boost.Spirit для Arduinos? – Maikel
- «Serial.printfn (« \ r \ nfound weather =% s »), погода; верный? если это не будет «Serial.printfn (« \ r \ nfound weather =% s », погода); ? – 12431234123412341234123