user2441297
user2441297

Reputation: 249

Parsing JSON POST request 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?

Upvotes: 5

Views: 12372

Answers (1)

Ryan M
Ryan M

Reputation: 2112

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();

Upvotes: 11

Related Questions