0

how can I read the JSON from this site (http://www.pegelonline.wsv.de/webservices/rest-api/v2/stations.json?includeTimeseries=true&includeCurrentMeasurement=true) in C# with the Json.net library? In this JSon there is only a array. I tested it with this code, but it doesn't work.

using (Stream stream = response.GetResponseStream())
{
  JsonReader reader = new JsonTextReader(new StreamReader(stream));
  dynamic info = JObject.Load(reader);
}

If i debug this, then VS says that the item is not an object. I try it with JArray.Load(reader); but then I don't know how to access the items.

1
  • Do you want to use only Json.net library or some other library solution are acceptable Commented Sep 21, 2013 at 15:13

1 Answer 1

1

You are right, JArray.Load is working correctly. The JArray then has a simple indexer to get to the individual items:

using (Stream stream = response.GetResponseStream())
{
  var reader = new JsonTextReader(new StreamReader(stream));
  var jsonArray = JArray.Load(reader);
  var item20 = jsonArray[19];
  var item20ShortName = (string)item20["shortname"];
}
Sign up to request clarification or add additional context in comments.

1 Comment

@user2025830 Adjusted the answer.

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.