开发者

JSON and LINQ Query

开发者 https://www.devze.com 2023-04-03 16:11 出处:网络
I am trying to parse the JSON file shown below, and get the coordinates of the place with specific name:

I am trying to parse the JSON file shown below, and get the coordinates of the place with specific name:

{"Theaters":[{"TheaterName":"Name1","GPSLocation":"3.888689,35.519845"},{"TheaterName":"Name2","GPSLocation":"33.867444,3.527002"},{"TheaterName":"Name3","GPSLocation":"33.897403,3.563645"},{"TheaterName":"Name4","GPSLocation":"34.438693, 3.831660"},{"TheaterName":"Name5","GPSLocation":"3.88392,35.48333"},{"TheaterName":"Name6","GPSLocation":"33.88424,35.483145"},{"TheaterName":"Name7","GPSLocation":"33.972802, 3.610099"},{"TheaterName":"Name8","GPSLocation":"33.857193,35.526886"},
{"TheaterName":"Name9","GPSLocation":"3.36394,35.735929"},{"TheaterName":"Name10","GPSLocation":"3.897403,35.563645"},{"TheaterName":"Name11","GPSLocation":"33.886605,3.508580"},{"TheaterName":"Name12","GPSLocation":"33.892134,3.517423"},
{"TheaterName":"Name13","GPSLocation":"3.917253,35.589074"},{"TheaterName":"Name14","GPSLocation":"33.2860,35.6115"}]}

The query i'm using is shown below, however the response is that expression couldn't be evaluated. What is the problem?? Thanks

var coordinates = from p in JSON["Theaters"].Children()
                                  where p["TheaterName"].Value<string>() == Name1
                                  sele开发者_运维问答ct p["GPSLocation"].Values();


Wouldn't you want the following?

var coordinates = from p in JSON["Theaters"].Children()
    where p["TheaterName"].Value<string>() == Name1
    select p["GPSLocation"].Value<string>();

After all, your GPSLocation is a comma separated list.


The you sett this response? In Visual Studio debugger? If so you'll seee the defered execution of LINQ queries. They get executed on the first access or you call the extension methos ToList(), ToArray() etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消