0

I would like to know , how we can parse a JSON data which is received from a rest web service. The sample JSON data is given here {"success":true, userName:true}

I am seeing numerous articles about this, as I am new to this, don't know the best method.

Thanks in advance Sebastian

Sebastian Xavier
  • 2,499
  • 7
  • 27
  • 41

3 Answers3

1

I propose you to build classes of your json or else you could go to this site and generate the classes.

a sample snippet would be like this:

public class RootObject
{
public Response response { get; set; }
}

public class Response
{
public int errorFlag { get; set; }
[JsonProperty("Score Detail")]
public JObject ScoreDetail { get; set; }
}

Have a look at this article fore more: http://blogs.msdn.com/b/africaapps/archive/2013/02/25/parsing-json-in-windows-phone-apps.aspx

Kulasangar
  • 9,046
  • 5
  • 51
  • 82
0

Json.NET makes this sort of thing super easy - https://www.nuget.org/packages/newtonsoft.json/

Lots of easy to follow examples here - http://james.newtonking.com/json/help/index.html

Gavin
  • 5,629
  • 7
  • 44
  • 86
0

If you are using visual studio 2013, you can directly generate the de-serialized class using the "paste as json" feature. You can then parse the json using this code

        public T GetObject(string json)
        {
            DataContractJsonSerializer jsonParser = new DataContractJsonSerializer(typeof(T));
            byte[] byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream = new MemoryStream(byteArray);
            var obj = jsonParser.ReadObject(stream);
            return (T)obj;
        }
bashrc
  • 4,725
  • 1
  • 22
  • 49