1

I have this code:

 public void ProcessRequest(HttpContext context)
 {
 var jsonSerializer = new JavaScriptSerializer();
 var jsonString = String.Empty;
 context.Request.InputStream.Position = 0;
 using (var inputStream = new StreamReader(context.Request.InputStream))
 {
 jsonString = inputStream.ReadToEnd();
 }
 }

Up code get json string and write in jsonString. jsonString result return

{"id":"54","name":"reza"}

How can i convert jsonString to JsonObject and parse it?

John Saunders
162k26 gold badges252 silver badges403 bronze badges
asked Jul 6, 2014 at 5:19
1

2 Answers 2

1

You can use NewtonSoft json library for c# and use below code

Create a class to hold the result

Class Person 
{
public int id {get;set;} 
public string name {get;set;} 
}
var person = JsonConvert.DeserializeObject<Person>(jsonString);
if you dont want to create class use JObject 
dynamic newObj = JObject.Parse(jsonString);
string id= newObj.id ;
string name= newObj.name;
answered Jul 6, 2014 at 5:51
Sign up to request clarification or add additional context in comments.

1 Comment

This works create with .net standard 1.0, and is probably the only serialization that works with this framework.
0

Solution 1 Use Newtonsoft.Json (Get package from here https://www.nuget.org/packages/newtonsoft.json/)

using (var inputStream = new StreamReader(context.Request.InputStream))
 {
 var jsonString = inputStream.ReadToEnd(); 
 var data = JsonConvert.DeserializeObject<Dictionary<string,string>>(jsonString);
 return data;
 }

Solution 2 Please follow the following Post

http://www.codeproject.com/Tips/79435/Deserialize-JSON-with-C

answered Jul 6, 2014 at 5:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.