2016-05-14 9 views
0

JSONが@Javascriptを作成し、AJAX経由でPHPに渡されました。問題は、JSON配列内の各JSONオブジェクトにキーを割り当てることができないことです。 JSON配列がこのようなものになります。 [{"jobId":"90","cname":"Subhasish","removal_id":101,"quantity":"3"},{"jobId":"90","cname":"Subhasish","removal_id":102,"quantity":"2"},{"jobId":"90","cname":"Subhasish","removal_id":103,"quantity":"4"},{"jobId":"90","cname":"Subhasish","removal_id":104,"quantity":"4"},{"jobId":"90","cname":"Subhasish","removal_id":105,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":106,"quantity":"5"},{"jobId":"90","cname":"Subhasish","removal_id":107,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":108,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":109,"quantity":"4"}]キーなしでPHPでJSON配列を読み取るには?

を、今、PHPで、どのようにデータを反復するために、私はPHPの初心者ですので、私は非常に愚かな質問をしていた場合、私をお許しください。

リンクにはキーの例があり、キーにはキーがありません。

ありがとうございます。

+4

参照してください..おかげで働いたhttp://stackoverflow.com/q/29308898/3933332 – Rizier123

答えて

1
$json = '[{"jobId":"90","cname":"Subhasish","removal_id":101,"quantity":"3"},{"jobId":"90","cname":"Subhasish","removal_id":102,"quantity":"2"},{"jobId":"90","cname":"Subhasish","removal_id":103,"quantity":"4"},{"jobId":"90","cname":"Subhasish","removal_id":104,"quantity":"4"},{"jobId":"90","cname":"Subhasish","removal_id":105,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":106,"quantity":"5"},{"jobId":"90","cname":"Subhasish","removal_id":107,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":108,"quantity":0},{"jobId":"90","cname":"Subhasish","removal_id":109,"quantity":"4"}]'; 
$array = json_decode($json,true); 
foreach($array as $item) { 
echo $item['jobId']."-".$item['cname']."-".$item['removal_id']."-".$item['quantity']."\n"; 
} 

Output 90-Subhasish-101-3 90-Subhasish-102-2 90-Subhasish-103-4 90-Subhasish-104-4 90-Subhasish-105-0 90-Subhasish-106-5 90-Subhasish-107-0 90-Subhasish-108-0 90-Subhasish-109-4

Example

+0

を – subhfyu546754

0

json_decode($ json_object)を使用しています。

$json = json_decode($json_object); 
foreach($json as $j){ 
    print_r($j) 
} 
関連する問題