I’m going to be passing some data between two devices, and wanted to use Json. I want to use a nested string, and i can’t figure out how to create it.
What exactly do you mean by “nested string”?
The sample code in the docs shows how to have a string nested inside a JSON object.
https://docs.particle.io/reference/device-os/firmware/photon/#jsonwriter
(in that sampel b & c are such strings)
This would be my example of a nested string
{
"request": {
"type": "Zipcode",
"query": "91321",
"language": "en",
"unit": "f"
},
"location": {
"name": "Newhall",
"country": "USA",
"region": "California",
"lat": "34.379",
"lon": "-118.521",
"timezone_id": "America/Los_Angeles",
"localtime": "2021-04-06 11:56",
"localtime_epoch": 1617710160,
"utc_offset": "-7.0"
},
"current": {
"observation_time": "06:56 PM",
"temperature": 59,
"weather_code": 116,
"weather_icons": [
"https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
],
"weather_descriptions": [
"Partly cloudy"
],
"wind_speed": 2,
"wind_degree": 26,
"wind_dir": "NNE",
"pressure": 1014,
"precip": 0,
"humidity": 49,
"cloudcover": 16,
"feelslike": 59,
"uv_index": 5,
"visibility": 6,
"is_day": "yes"
},
"forecast": {
"2021-04-05": {
"date": "2021-04-05",
"date_epoch": 1617580800,
"astro": {
"sunrise": "06:35 AM",
"sunset": "07:19 PM",
"moonrise": "03:16 AM",
"moonset": "01:17 PM",
"moon_phase": "Waning Crescent",
"moon_illumination": 34
},
"mintemp": 59,
"maxtemp": 77,
"avgtemp": 68,
"totalsnow": 0,
"sunhour": 11.6,
"uv_index": 8
}
}
}
or
{
"a": {
"inner1": 123,
"inner2": 456
},
"b": {
"Outer1": 135,
"Outer2": 468
}
}
writer.beginObject();
writer.name("a");
writer.beginObject();
writer.name("a1").value(1);
writer.name("a2").value(1);
writer.name("a3").value(1);
writer.endObject();
writer.name("b");
writer.beginObject();
writer.name("b1").value(1);
writer.name("b2").value(1);
writer.name("b3").value(1);
writer.endObject();
writer.endObject();
4 Likes
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.