I try to combine 2 tables of database to a json object, I think it is maybe a 3D array
like this↓
table_1 ->(name:"Ken"),(gender:"male")
table_2 ->(name:"Lon"),(gender:"male")
table_1 and 2 is 1st dimension, name and gender is 2nd dimension, ken and male is 3rd dimension
so, I made a json object wiht PHP "json_encode()", and try to parse it with javascript
json object:
{
"client_infos":[ {
"client": {
"no": 1, "C_name": "ken", "input_date": "2017-07-20 13:44:46", "total_price": 123
}
,
"item_lists":[["item_list",
{
"no": 1, "rs_no": 1, "item_name": "ApplePie", "item_quantity": 2, "unit_price": 10
}
],
["item_list",
{
"no": 2, "rs_no": 1, "item_name": "BananaCow", "item_quantity": 3, "unit_price": 5
}
]]
}
,
{
"client": {
"no": 3, "C_name": "ken", "input_date": "2017-07-20 14:24:26", "total_price": 200
}
,
"item_lists":[["item_list",
{
"no": 5, "rs_no": 3, "item_name": "LimeMilk", "item_quantity": 5, "unit_price": 33
}
]]
}
]
}
how do I parse it ? for example, I want to extract the data of 2nd client and item_lists.
I have been using JSON.parse(json), but I have no idea how to get the value.
var content = JSON.parse(res);
console.log(content.client_infos.client[1].no);
it's not work.
var object = JSON.parse(variableOrStringLiteral);
finally, I find out the right way to get the value that like this
var obj = JSON.parse(content);
obj.client_infos[0].client.no;