2016-10-05 22 views
-4

レスポンスを図示の形式で送信する必要があります。Json APIレスポンス

{ "order":{ "orderList":[ { "dishID":"2", "dishQuantity":"1", "dishPrice":"120" }, { "dishID":"3", "dishQuantity":"1", "dishPrice":"120" } ], "order_no":"12345", "order_date":"" }, "order":{ "orderList":[ { "dishID":"2", "dishQuantity":"1", "dishPrice":"120" }, { "dishID":"3", "dishQuantity":"1", "dishPrice":"120" } ], "order_no":"67890", "order_date":"" } } 

ループしながら、データには、そのJSON形式のデータを表示する方法を助けてください、ネストされた使用しています。

+1

Json_encode();? – james

+0

json_encode技術を試してみましたか? – Keerthivasan

+0

これは有効なjsonではありません... –

答えて

0

この

$Array1 = array(
0 => array(
    "order" => array(
     "orderList"=> array(
      0 => array(
      "dishID"=> "2", 
      "dishQuantity"=> "1", 
      "dishPrice"=> "120" 
     ), 
      1 => array(
      "dishID"=> "3", 
      "dishQuantity"=> "1", 
      "dishPrice"=> "120" 
     ) 
     ), 
     "order_no" => "67890", 
     "order_date" => "" 
    ) 
), 
1 => array(
    "order" => array(
     "orderList"=> array(
      0 => array(
      "dishID"=> "2", 
      "dishQuantity"=> "1", 
      "dishPrice"=> "120" 
     ), 
      1 => array(
      "dishID"=> "3", 
      "dishQuantity"=> "1", 
      "dishPrice"=> "120" 
     ) 
     ), 
     "order_no" => "67890", 
     "order_date" => "" 
    ) 
) 
); 

$jsonEncodedArray = json_encode($Array1); 
0

あなたは、配列の形式があるとしてみてください。このようjsoneする

$arrayData = stdClass Object 
    (
    [order] => stdClass Object 
     (
      [orderList] => Array 
       (
        [0] => stdClass Object 
         (
          [dishID] => 2 
          [dishQuantity] => 1 
          [dishPrice] => 120 
         ) 

        [1] => stdClass Object 
         (
          [dishID] => 3 
          [dishQuantity] => 1 
          [dishPrice] => 120 
         ) 

       ) 

      [order_no] => 67890 
      [order_date] => 
     ) 

) 

変換配列:

json_encode($ arrayDataを)。

関連する問題