-1

I use geobytes api to find nearby city

http://gd.geobytes.com/GetNearbyCities?&radius=220&limit=3

api result is 2 dimension json array without attribute name

[
    ["0.00", "Phuket", "PU", "Thailand", "North", "0.00", "TH", "0.00", "7.883000", "THPUPHUK", "98.400002", "0.00", "Phuket"],
    ["35.90", "Surat Thani", "ST", "Thailand", "North-East", "92.72", "TH", "171.72", "9.133000", "THSTSTHA", "99.317001", "106.70", "Surat Thani"]
]

How can I get a list of city names from this json result with newtonsoft json ?

Thanks!

2
  • Is that valid JSON? Commented Feb 15, 2017 at 8:25
  • There are a ton of answers for this quesion here on stackoverflow. Use the search and you'll find a lot. e.g. this Commented Feb 15, 2017 at 8:35

1 Answer 1

0

You should do the following:

     string[][] geobytesResponse = JsonConvert.DeserializeObject<string[][]>(geobytesResponseString);
     const int cityIndexInCityInfoArray = 1;
     string[] cityNames = geobytesResponse.Select(cityInfoArray => cityInfoArray[cityIndexInCityInfoArray]).ToArray();
Sign up to request clarification or add additional context in comments.

2 Comments

thanks yar_shukan. this help me a lot. but 2nd Array can not use Select. Then I try something like this : foreach (cityNames[] city in cities) { nearbyCityList.Add(city[1]); }
@user3338721 what do you mean by 2nd Array can't use .Select? If this helped you, I think the best way you can thank you is upvote and accept this as an answer. thx

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.