multiple json data parasing

My json data looks like this

{"name":"Switch 1","status":0,"id":1},{"name":"Switch 2","status":1,"id":2},{"name":"Switch 3","status":0,"id":3},{"name":"Switch 4","status":0,"id":4}

i want to parase every object but it only parases single json data..

this is the output which i got

name
Switch 1
status
0
id
1

please help me out :confused:

anbu123:
My json data looks like this

{"name":"Switch 1","status":0,"id":1},{"name":"Switch 2","status":1,"id":2},{"name":"Switch 3","status":0,"id":3},{"name":"Switch 4","status":0,"id":4}

i want to parase every object but it only parases single json data..

this is the output which i got

name
Switch 1
status
0
id
1

please help me out :confused:

I suppose you are using some kind of library to do this?

:confused:

yes here i used #include <ArduinoJson.h> library

this is part which parase json data
JsonObject& root = jsonBuffer.parseObject(jsondata);
for (auto kv : root) {
Serial.println(kv.key);
Serial.println(kv.value.as<char*>());
}

anbu123:
yes here i used #include <ArduinoJson.h> library

this is part which parase json data
JsonObject& root = jsonBuffer.parseObject(jsondata);
for (auto kv : root) {
Serial.println(kv.key);
Serial.println(kv.value.as<char*>());
}

it is "parse" not "parase"

at this point you may be encouraged by forum members to post your code so people could diagnose your problem...

let's see what happens.

sorry for my bad English

You do not have ONE json object. You have 4 json objects. You need to parse each one independently.

How can I parse each data independently?
Can you tell me one example??

anbu123:
How can I parse each data independently?
Can you tell me one example??

[{"name":"Switch 1","status":0,"id":1},{"name":"Switch 2","status":1,"id":2},{"name":"Switch 3","status":0,"id":3},{"name":"Switch 4","status":0,"id":4}]

[{"name":"Switch 1","status":0,"id":1},{"name":"Switch 2","status":1,"id":2},{"name":"Switch 3","status":0,"id":3},{"name":"Switch 4","status":0,"id":4}]

i tried this way also.But i got only one json object as output.
how can i parse all json data??

You have to properly structure the JSON data. The last attempt produces an anonymous array of objects. Don't do that. Produce a named array of objects.

{"topLevel":
          [
             {"name":"Switch 1","status":0,"id":1},
             {"name":"Switch 2","status":1,"id":2},
             {"name":"Switch 3","status":0,"id":3},
             {"name":"Switch 4","status":0,"id":4}
          ]
}

PaulS:
You have to properly structure the JSON data. The last attempt produces an anonymous array of objects. Don't do that. Produce a named array of objects.

{"topLevel":

[
            {"name":"Switch 1","status":0,"id":1},
            {"name":"Switch 2","status":1,"id":2},
            {"name":"Switch 3","status":0,"id":3},
            {"name":"Switch 4","status":0,"id":4}
          ]
}

how can i parse?can i use the same method for parse json data?

can i use the same method for parse json data?

You have my permission to do that.

thanks to all..
i got ouput when i am putting output in a for loop

StaticJsonBuffer<1200> jsonBuffer;
JsonArray& root = jsonBuffer.parseArray(anbu);

if (!root.success())
{
Serial.println("parseArray() failed");
return;
}
int j = 0, id, ss,rr;
for (j=0;j<4;j++)
{
id = root.get(j)["id"];
ss = root.get(j)["status"];
rr = root.get(j)["name"];
Serial.print("ID = "); Serial.print(id); Serial.print(" status = "); Serial.print(ss);
}

help me!
i try parsing json with serial input arduino, and i input in serial it:
{"id":"1","stat":"on"}{"id":"2","stat":"off"}{"id":"3","stat":"off"}{"id":"4","stat":"on"}

this is my arduino program:

#include <ArduinoJson.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(2000);
}

void loop() {
if(Serial.available() > 0)
{
String inData[] = Serial.readStringUntil('\n');
Serial.println(inData);

StaticJsonBuffer<1200> jsonBuffer;
JsonArray& root = jsonBuffer.parseArray(inData);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
for (int i = 0; i < sizeof(root); i++) {

Serial.print(i);
Serial.println(root*["stat"]);*

  • }*
  • }*
    }
    but i have problem, i compilling verry slow, 1 hour is not done compilling... help me
    i use arduino Uno
    nurramdandoni@gmail.com
        String inData[] = Serial.readStringUntil('\n');

The readStringUntil() crutch (oops, I meant method) does NOT return an array of Strings.

       StaticJsonBuffer<1200> jsonBuffer;

Do you REALLY expect to type in 1200 characters to the Serial Monitor app?

{"id":"1","stat":"on"}{"id":"2","stat":"off"}{"id":"3","stat":"off"}{"id":"4","stat":"on"}

Is NOT valid JSON.

but i have problem, i compilling verry slow, 1 hour is not done compilling... help me
i use arduino Uno

If you quit using more than all the memory on the Arduino, I suspect that compilation would complete in nothing flat.

There is something wrong with your computer/installation if it takes more than a few seconds to compile (and fail) that code.