Hey again guys!
I’ve been fixing this error since yesterday and until now I can’t still fix it.
I already checked the response by printing it in a label (as you can see behind that notif) and I still don’t know why it gets error.
This is my blocks:
Here is the response from label:
Rogerio_Rios
(Professional Support)
October 4, 2021, 11:22am
#20
1-Your php return is right?
2- Click and DO IT on the blue block “list of pairs to …”
What do you get as a result?
3- Click on DO IT in the blocks below: Get Value for Key…
Rogerio_Rios
(Professional Support)
October 4, 2021, 11:41am
#21
Using a Json:
[{“plate_num”:“30”,“b_class”:“Class 3 Unit”,“b_dep”:“9:30”,“b_arriv”:“11:30”,“b_driv”:“Arnel Ignacio”},
{“plate_num”:“20”,“b_class”:“Class 5 Unit”,“b_dep”:“8:30”,“b_arriv”:“12:30”,“b_driv”:“Juan Pedro”}]
and Lookup Pairs Key Block
4 Likes
The Do It is not working for me idk y
Rogerio_Rios
(Professional Support)
October 4, 2021, 11:49am
#23
Connect to Companion…
Check your JSON return from your PHP :
Nobody knows what you did.
There are 2 PHP Scripts ( here in community )ready to help beginners.
You do not need an extension to access Mysql. OK ?
In web got, you will have to use response Content (this is where you will have the data returned from your Script). You can use the response code to check the return code
You can use the Json Decode text Block to handle Response Content.
You can use dictionary blocks.
You can use lookup pairs Key together with Json Decode text to get values by…
my companion always stops, I’m just using an emulator
I already adjusted that blocks awhile ago this is now my current blocks:
and I always got this:
Rogerio_Rios
(Professional Support)
October 4, 2021, 12:23pm
#27
Did you check your Json here ?
HritikR
(🧩)
October 4, 2021, 12:25pm
#28
can you share your AIA? post it here or at least share your API endpoint
Yes and this is the result:
{
"bus":[
{
"Bus_Plate_Number":"30",
"Bus_Class":"Class 3 Unit",
"Bus_Branch":"Calbayog",
"Bus_Route":"Allen",
"Bus_Dep_Time":"9:30 AM",
"Bus_Arriv_Time":"11:30 AM",
"Bus_Driver":"Arnel Ignacio",
"Bus_Contact":"09123456789",
"Bus_DateAdded":"2021-08-07"
}
]
}{
"bus":[
{
"Bus_Plate_Number":"30",
"Bus_Class":"Class 3 Unit",
"Bus_Branch":"Calbayog",
"Bus_Route":"Allen",
"Bus_Dep_Time":"9:30 AM",
"Bus_Arriv_Time":"11:30 AM",
"Bus_Driver":"Arnel Ignacio",
"Bus_Contact":"09123456789",
"Bus_DateAdded":"2021-08-07"
},
{
"Bus_Plate_Number":"35",
"Bus_Class":"Class 3 Unit",
"Bus_Branch":"Calbayog",
"Bus_Route":"Allen",
"Bus_Dep_Time":"9:30 AM",
"Bus_Arriv_Time":"11:30 AM",
"Bus_Driver":"Efren Catalan",
"Bus_Contact":"09123456789",
"Bus_DateAdded":"2021-08-07"
}
]
}
HritikR
(🧩)
October 4, 2021, 12:29pm
#31
you need to make some changes in your php code for generating valid json.
1 Like
Rogerio_Rios
(Professional Support)
October 4, 2021, 12:30pm
#32
dora_paz:
This is not a valid json
I already warned you about this…
I’ve already shown you the topic about JSON…
Showed the link to test JSON…
But it seems that the users here on the forum want to solve it in a few minutes…
4 Likes
Sorry, the app that I’m generating right now is part of my thesis that’s why I’m really eager to solve the problem quickly. I’m currently adjusting the php file right now. This JSON is really new to me that’s why I always got this error since last week.
(post deleted)
Already Rogerio shared a site . Please make use of it and correct your json
Rogerio_Rios
(Professional Support)
October 4, 2021, 12:52pm
#35
What he needs is to adjust the php script that generates the JSON.
2 Likes
I already knew what’s the valid json. The only problem is how I will correct it through php. This is my code:
$conn = new mysqli($host,$username,$password,$dbname);
$data = mysqli_query($conn, "SELECT * FROM bus WHERE Bus_Dep_Time='9:30 AM' AND Bus_Branch='Calbayog'");
$array = array();
while ($result=mysqli_fetch_assoc($data))
{
$array['bus'][]=$result;
echo json_encode($array);
}
I keep adjusting the $array[‘bus’] =$result; but I always got the wrong json