2017-04-10 162 views
0

我有.asmx web服務和方法。但我不確定是否返回json。Web服務返回json或xml?

它作爲Json返回嗎?

<string xmlns="http://tempuri.org/"> 
{ "Table": [ { "Key1": "x", "Key2": "x", "Key3": "Ads" } ], "Key4": [ { "Key41": "30", "Key42": "12", "Key43": "1" } ], "Key5": [ { "Key51": "10.4.2017 00:00:00" } ] } 
</string> 

所以方法結果頁面寫道,文字上方:

This XML file does not appear to have any style information associated with it. The document tree is shown below. 

我能得到這個數據作爲JSON?

回答

0

可以幫這個

$cont_data = array("Table"=>array("Key1"=> "x", 
 
      "Key2"=> "x", 
 
      "Key3"=> "Ads" 
 
     ), 
 
     "Key4"=>array( 
 
        "Key41"=> "30", 
 
        "Key42"=> "12", 
 
        "Key43"=> "1" 
 
      ), 
 
     "Key5"=>array( 
 
       "Key51"=>"10.4.2017 00:00:00" 
 
      ) 
 
); 
 
    
 
    return json_encode($cont_data);

你可以得到JSON作爲結果,json_decode()做到這一點。

+0

不,我想返回類型。是xml還是json – ymymym

+0

更新了答案。 –