2016-10-05 9 views
-4

Ich muss Antwort im angezeigten Format senden.Json API Antwort

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

Daten verschachtelt kommt Verwendung while-Schleife, so helfen Sie bitte, wie in diesem JSON-Format Daten anzuzeigen.

+1

Json_encode() ;? – james

+0

hast du die json_encode techniken ausprobiert? – Keerthivasan

+0

das ist kein gültiger JSON ... –

Antwort

0

versuchen diese

$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

nehme an, Sie Array dieses Format haben:

$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] => 
     ) 

) 

convert Array wie folgt jsone:

json_encode ($ arrayData);