Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing JSON POST request C#

Tags:

json

c#

Some serwer sends POST requests with the following information:

{
    payload: {
    uid: "900af657a65e",
    amount: 50,
    adjusted_amount: 25
},
 signature: "4dd0f5da77ecaf88628967bbd91d9506"
}

How shoud I successfully process that in my ASHX handler?

like image 281
user2441297 Avatar asked Jun 20 '13 18:06

user2441297


1 Answers

As SLaks noted, that's not valid JSON. But in general, a good solution for serializing/deserializing JSON in .NET is the JSON.NET library: http://json.codeplex.com/. There is plenty of documentation there that should get you started.

Edit: to read the request body, try something like

 string postData = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();
like image 76
Ryan M Avatar answered Nov 01 '22 19:11

Ryan M