How ArduinoEthernet read data from JSON when data obtained from database hosting

Can I read data from json using Arduino and ethernet…
when json data is obtained from mysql database hosting…

my php code looks like this…

<?php
    //open connection to mysql db
    $connection = mysqli_connect("localhost","youngzy_one","****","mo_bus") or die("Error " . mysqli_error($connection));

    //fetch table rows from mysql db
    $sql = "select * from tabeldata";
    $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

    //create an array
    $emparray = array();
    while($row =mysqli_fetch_assoc($result))
    {
        $emparray[] = $row;
    }
    //write to json file
    $fp = fopen('light.json', 'w');
    fwrite($fp, json_encode($emparray));
    fclose($fp);
    //close the db connection
    mysqli_close($connection);
?>

This is what i get inside a Json

[{"id":"1","temp":"22","humi":"10"},{"id":"2","temp":"23","humi":"30"},{"id":"3","temp":"30,"humi":"22"}]

what i want is, how to read this json data using arduino and ethernet shield…
and print’it to the serial monitor…

I’m sorry, my english is not very good …
any response is greatly appreciated … thanks :slight_smile:

Can I read data from json using Arduino and ethernet..

"from json" doesn't make sense. The data that the Arduino gets may, or may not, be in JSON format.

This is what i get inside a Json

"inside a Json" makes no sense. That is some data in JSON format.

how to read this json data using arduino and ethernet shield..

One character at a time, just like any other data.

so what should i do.. to make arduino can get data from my hosting database?
honestly i'm still new to arduino...

I have modified the lighting by using a web condition with esp8266 at this link .. by using ethernet, and I can do it ..

the light condition is determined by the status on json .. so I thought if I could modify the json status by retrieving data from the database.. so i modify it and i can do it, and the json result can be seen as I have mentioned before,..
so the problem is what should i do to make arduino read this json status, can the arduino read it?

so what should i do.. to make arduino can get data from my hosting database?

Attach the right hardware and write the right code.

so the problem is what should i do to make arduino read this json status

Forget about the fact that the data is in JSON format. That is COMPLETELY irrelevant.

can the arduino read it?

Of course it can.

Why the hell is should is a completely separate question. Why pass that huge stream of data in JSON format when all the Arduino wants to know is whether the turn a pin on or off (or brighter/dimmer)?

I’m sorry if what I had done wrong … because i still new with arduino…
so what should I do if I want to make arduino, can receive data from database hosting?
are you have a reference for this?

anyway thank you for your response…

so what should I do if I want to make arduino, can receive data from database hosting?

Do you have an ethernet shield? If so, look at the client example. Change the server in the example to the server hosting your PHP script and the GET request to call your script.

yes i have ethernet shield...
in my case, i need two way data stream..
the first thing is to send data from my arduino and store it to my hosting database..
and i succed to do it..
the second thing is how to make arduino receive data from my database..
this is my actual problem..
i'm stuck at get request, and don't have a good reference..
many reference is just explain how to send data to hosting, not otherwise..
do you have any example of it?

i'm stuck at get request

This means that you have some code, and that the code does something. You have shared neither one.

What you need is a JSON library for arduino. There are several: google it.

Once you have this library, you will need to READ THE DOCUMENTATION. It will have a way of parsing data from a connection and creating an object, and that object will have ways of accessing the data inside it.

Note that it will be very important to dispose of these things after you are done with them. If you don't, the memory will fill up and everything will just stop.

But simply: this is a complicated job, you will need to use a library.