0

I am working in C#. I want to parse JSON in my application. But have no idea how to parse Json. I have search a lot on Google But couldn't find enough material. My JSOn is ..

[{"id":"267","name":"Macmillan Nursing Service","telephone":"01595 743347",
"addr1":"Gilbert Bain Hospital","town":"Shetland","postcode":"ZE1 0TB",
"lat":"60.1505513","lng":"-1.1546642","distance":"3278.42778426762"},

{"id":"355","name":"Orkney Macmillan House","telephone":"01856 888249",
"addr1":"Balfour Hosptial","town":"","postcode":"KW15 1BH","lat":"58.9767143",
"lng":"-2.9649377","distance":"3421.52913012431"},

{"id":"57",
"name":"Community Macmillan Nurse","telephone":"01779 482568",
"addr1":"Peterhead Health    Centre","town":"Peterhead",
"postcode":"AB422XA","lat":"57.5034159","lng":"-1.7939854",
"distance":"3425.64696427705"},

{"id":"287","name":"Macmillan
Service","telephone":"01955 880397","addr1":"Caithness
General Hospital","town":"Wick","postcode":"KW1 5NS","lat":"58.4415",
"lng":"-3.09651","distance":"3452.34795736445"},

{"id":"288","name":"Macmillan Service",
"telephone":"01888 564015","addr1":"The Health Centre","town":"Banff","postcode":"AB45  
1HY","lat":"57.6686963","lng":"-2.5256111","distance":"3457.45181828202"}]

I am stuck in this work kindly help me out..

Any help would be great. Or a little clue about how to parse Json will also be enough.

6
  • 2
    What do you mean, "remotely"? What is local and what is remote in this instance? Commented Dec 20, 2012 at 11:18
  • What do you mean by "Parse JSON remotely"? I think your wording may be misleading if what you want to do is download a JSON string and then work with it locally... Commented Dec 20, 2012 at 11:18
  • well i just want to access this json from internet here is the link ..myhealthpal.com/charity_app/… Commented Dec 20, 2012 at 11:19
  • You can use the JSON.Net library. Or DataContractJsonSerializer in C#. Commented Dec 20, 2012 at 11:19
  • this Json is coming from internet and i want to show it in a list or gridview Commented Dec 20, 2012 at 11:20

2 Answers 2

3

Use a brilliant Json.net library.

Features

Flexible JSON serializer for converting between .NET objects and JSON
LINQ to JSON for manually reading and writing JSON
High performance, faster than .NET's built-in JSON serializers
Write indented, easy to read JSON
Convert JSON to and from XML
Supports .NET 2, .NET 3.5, .NET 4, Silverlight and Windows Phone

The serializer is a good choice when the JSON you are reading or writing maps closely to a .NET class.

LINQ to JSON is good for situations where you are only interested in getting values from JSON, you don't have a class to serialize or deserialize to, or the JSON is radically different from your class and you need to manually read and write from your objects.

Sign up to request clarification or add additional context in comments.

5 Comments

Well this answer doesn't seems enough .. Because i have already read it out.. I want a little coding if someone can ...
@BurhanMughal How is this answer not enough? You stated you do not know how to parse JSON, Jakub provided information regarding a popular library for doing just that, Parsing JSON.
I was jsut looking the answer like the Answer from Kami.. Thanx anyway to Jakub ..
@BurhanMughal - Have you clicked on the link provided? There is a sample there... and a performance comparison with JavaScriptSerializer
@ Well brother Just consider me the nieve user and u may come to know that waht I m Looking for.
2

It seems like you need to de-serialise a JSON string to an object. You can create create a class that represents the object, and then de-serialise the json to it.

Something like

class Information
{
   int id;
   string name;
   string telephone;
   // etc
}

Then de-serialise with something like this

JavaScriptSerializer json_serializer = new JavaScriptSerializer();
// Using List<T> as the JSON is organised like an array
List<Information> info = (List<Information >)json_serializer.DeserializeObject(JSONFeed);

Where JSONFeed is your json string from the website.

For a more indepth aproach see - Tutorial on Code Project

2 Comments

Yes this is what i was looking for I have made the class already but couldn't know how to extract data from website ..
Are you not able to download the data? That is a different question from what you are asking.

Your Answer

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.