【问题标题】:How to get php json data in c# using webAPI?如何使用 webAPI 在 c# 中获取 php json 数据?
【发布时间】:2016-08-28 04:17:12
【问题描述】:

我使用这个 php 代码将我的数据作为参数发送

 $jsonData  = json_encode(array('shenase'=>$shenase,'fullname'=>$name,'nikokarhaghighi'=>$nikokarhaghighi,'nikokarhoghoghi'=>$nikokarhoghoghi,
'stateone'=>$stateone,'questionone'=>$questionone,'questiontwo'=>$questiontwo,
'statethree'=>$statethree,'stateFour'=>$stateFour,'statefive'=>$statefive));

我想像这样在我的网址末尾添加$jsonData

(...../check/checkdata?data=' . $jsonData).

我使用 webAPI 来获取这个$jsonData。如何在 C# 中获取这些数据?

【问题讨论】:

    标签: c# php json asp.net-web-api


    【解决方案1】:

    有两种方法可以做到这一点。一种是创建由您的 PHP 代码发送的数据模型。即

    class Model
    {
    public string shenase{get; set;}
    public string fullname{get; set;}
    // rest of the properties
    }
    

    在你的 C# WEB API

    public HttpResponseMessage YourEndPoint([FromUri]Model model)
    {
    //this will atuomatically bind values sent in URL to model
    }
    

    其他方式在你的 C# WebAPI 中,而不是创建模型只是创建相应的参数,即

    public HttpResponseMessage YourEndPoint(string fullname, string shenase, ...)
    {
    //this will atuomatically bind values sent in URL to model
    }
    

    详情请访问WEB API model binding

    【讨论】:

      猜你喜欢
      • 2015-01-05
      • 2023-03-16
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      相关资源
      最近更新 更多