balouchi balouchi - 3 months ago 18
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,
'stateone'=>$stateone,'questionone'=>$questionone,'questiontwo'=>$questiontwo,
'statethree'=>$statethree,'stateFour'=>$stateFour,'statefive'=>$statefive));


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

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


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

Answer

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.