Json

Hello to everybody?

I am trying to use the Json library (GitHub - bblanchon/ArduinoJson: 📟 JSON library for Arduino and embedded C++. Simple and efficient.) to parse this Json data... but with no success...

{"HourlyAirQualityIndex":{"@TimeToLive":"32","LocalAuthority":{"@LocalAuthorityName":"Westminster","@LocalAuthorityCode":"33","@LaCentreLatitude":"51.509645","@LaCentreLongitude":"-0.158586","@LaCentreLongitudeWGS84":"-17653.712767","@LaCentreLatitudeWGS84":"6711944.006712","Site":{"@LatitudeWGS84":"6709694.46727186","@LongitudeWGS84":"-15856.2169939846","@Longitude":"-0.142438820740121","@Latitude":"51.497066177578","@SiteType":"Urban Background","@SiteCode":"WM8","@SiteName":"Westminster - Victoria","@BulletinDate":"2014-08-06 19:00:00","species":{"@SpeciesName":"Nitrogen Dioxide","@SpeciesCode":"NO2","@AirQualityIndex":"1","@AirQualityBand":"Low","@IndexSource":"Measurement"}}}}}

I am interesting to read the status of AirQualityBand:Low ... etc

can you help me? thanx :slight_smile:

can you help me?

No. You haven't posted any code. You haven't explained what the problem is.

Ok let me be more specific...

I have this Json parser...

/*
* Arduino JSON library - Parser Example
* Benoit Blanchon 2014 - MIT License
*/

#include <JsonParser.h>

using namespace ArduinoJson::Parser;

void setup()
{
    Serial.begin(9600);

    char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";

    JsonParser<16> parser;

    JsonObject root = parser.parse(json);

    if (!root.success())
    {
        Serial.println("JsonParser.parse() failed");
        return;
    }

    char*  sensor    = root["sensor"];
    long   time      = root["time"];
    double latitude  = root["data"][0];
    double longitude = root["data"][1];

    Serial.println(sensor);
    Serial.println(time);
    Serial.println(latitude, 6);
    Serial.println(longitude, 6);
}

void loop()
{

}

and i have this json string...

{"HourlyAirQualityIndex":{"@TimeToLive":"19","LocalAuthority":{"@LocalAuthorityName":"Westminster","@LocalAuthorityCode":"33","@LaCentreLatitude":"51.509645","@LaCentreLongitude":"-0.158586","@LaCentreLongitudeWGS84":"-17653.712767","@LaCentreLatitudeWGS84":"6711944.006712","Site":{"@LatitudeWGS84":"6709694.46727186","@LongitudeWGS84":"-15856.2169939846","@Longitude":"-0.142438820740121","@Latitude":"51.497066177578","@SiteType":"Urban Background","@SiteCode":"WM8","@SiteName":"Westminster - Victoria","@BulletinDate":"2014-08-07 11:00:00","species":{"@SpeciesName":"Nitrogen Dioxide","@SpeciesCode":"NO2","@AirQualityIndex":"2","@AirQualityBand":"Low","@IndexSource":"Measurement"}}}}}

i don't know how can i filter this string using maybe the json parser to read the value of the AirQualityBand: xxx

the json data is from this url: http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/SiteCode=WM8/Json

Arduino reads from that file from internet and i want to read specific the value of the AirQualityBand: myValue

thank you!

I have this Json parser...

which parses a string:

    char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";

You have this string:

{"HourlyAirQualityIndex":{"@TimeToLive":"19","LocalAuthority":{"@LocalAuthorityName":"Westminster","@LocalAuthorityCode":"33","@LaCentreLatitude":"51.509645","@LaCentreLongitude":"-0.158586","@LaCentreLongitudeWGS84":"-17653.712767","@LaCentreLatitudeWGS84":"6711944.006712","Site":{"@LatitudeWGS84":"6709694.46727186","@LongitudeWGS84":"-15856.2169939846","@Longitude":"-0.142438820740121","@Latitude":"51.497066177578","@SiteType":"Urban Background","@SiteCode":"WM8","@SiteName":"Westminster - Victoria","@BulletinDate":"2014-08-07 11:00:00","species":{"@SpeciesName":"Nitrogen Dioxide","@SpeciesCode":"NO2","@AirQualityIndex":"2","@AirQualityBand":"Low","@IndexSource":"Measurement"}}}}}

Ask yourself which part of your string is equivalent to sensor in the string that can be parsed. If you say HourlyAirQualityIndex, pat yourself on the back.

Now, look at what is being used as the indexes into the root "array". What would be the equivalent names for you to use?

Perhaps organizing your string a little differently would help:

{
	"HourlyAirQualityIndex":
	{
		"@TimeToLive":"19",
		"LocalAuthority":
		{
			"@LocalAuthorityName":"Westminster",
			"@LocalAuthorityCode":"33",
			"@LaCentreLatitude":"51.509645",
			"@LaCentreLongitude":"-0.158586",
			"@LaCentreLongitudeWGS84":"-17653.712767",
			"@LaCentreLatitudeWGS84":"6711944.006712",
			"Site":
			{
				"@LatitudeWGS84":"6709694.46727186",
				"@LongitudeWGS84":"-15856.2169939846",
				"@Longitude":"-0.142438820740121",
				"@Latitude":"51.497066177578",
				"@SiteType":"Urban Background",
				"@SiteCode":"WM8",
				"@SiteName":"Westminster - Victoria",
				"@BulletinDate":"2014-08-07 11:00:00",
				"species":
				{
					"@SpeciesName":"Nitrogen Dioxide",
					"@SpeciesCode":"NO2",
					"@AirQualityIndex":"2",
					"@AirQualityBand":"Low",
					"@IndexSource":"Measurement"
				}
			}
		}
	}
}

Lets try again.. to understand exactly what i want to do...

Arduino with ethernet shield (using WIZnet library) reads that url: http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/SiteCode=WM8/Json

i want to filter this data. I want only to read the AirQualityBand: x ( x = Low, Moderaty, High, Very High)

So,

if it is "Low" do something....
if it is "Moderate" do something... etc....

How can i do that? with a Json parser?

How can i do that? with a Json parser?

With the JSON parser you linked, you can not, unless you read and store the complete string (not String).

If you want to read each character from the response, and store data starting with the @, and determining whether the identifier is for the data of interest when the " arrives, and, if so, storing the data from the next " to the one after that, then the stored data would be the quality value.

I seems quite difficult for me to make this out with Json data format. Finally I use a simple XML parser to continue with my project... Thanx for the help anyway!!!! :slight_smile:

but I still get this error.

That is CLEARLY a WARNING, not an ERROR!