【问题标题】:Web Service returns json or xml?Web 服务返回 json 还是 xml?
【发布时间】:2023-03-22 06:00:02
【问题描述】:

我有 .asmx 网络服务和方法。但我不确定是否返回 json。

它会以 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 获取吗?

【问题讨论】:

    标签: json xml web service


    【解决方案1】:

    可以帮助这个人

    $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()这样做。

    【讨论】:

    • 没有。我想返回类型。是xml还是json
    • 更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2012-02-26
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    相关资源
    最近更新 更多