balouchi balouchi - 1 year ago 142
C# Question

How to get php json data in c# using webAPI?

I use this php code to send my data as parameter

$jsonData = json_encode(array('shenase'=>$shenase,'fullname'=>$name,'nikokarhaghighi'=>$nikokarhaghighi,'nikokarhoghoghi'=>$nikokarhoghoghi,

I want to add this
at the end of my url like this

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

I use webAPI to get this
. How can I get this data in C# ?

Answer Source

There is two way you can do this. One is creating a model of data sent by your PHP code. i.e

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

In you C# WEB API

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

Otherway is in you C# WebAPI instead of creating model just create corresponding parameters i.e.

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

For detail please visit WEB API model binding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download