2017-07-21 66 views
-3

我嘗試數據庫的2個表組合成JSON對象,我認爲這也許是一個三維陣列如何創建一個三維數組並將其解析?

這樣↓

TABLE_1 - >(名稱:「肯」),(性別:「男「)

TABLE_2 - >(名:」 經度 「),(性別:」 男「)

TABLE_1和2被第一尺寸,姓名,性別是第二維, Ken和男性是第三維

所以,我做了一個json對象wih牛逼PHP 「json_encode()」,並嘗試與JavaScript

JSON對象解析它:

{ 
"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 
    } 
    ]] 
} 
] 

}

我怎麼分析呢?例如,我想提取第二個客戶端和item_lists的數據。

我一直在使用JSON.parse(json),但我不知道如何獲取值。

var content = JSON.parse(res); 
console.log(content.client_infos.client[1].no); 

這是行不通的。

+0

你怎麼什麼解析它的價值呢? PHP? [json_decode](http://php.net/json_decode)。 JavaScript的?這取決於JS如何得到它,而你沒有看到它。還有別的嗎? –

回答

1
var object = JSON.parse(variableOrStringLiteral); 
0

終於,我找到了正確的方式來獲得,像這樣

var obj = JSON.parse(content); 
obj.client_infos[0].client.no; 
相關問題