Skip to content

Instantly share code, notes, and snippets.

@numa08
Created September 6, 2012 16:11
Show Gist options
  • Save numa08/3657968 to your computer and use it in GitHub Desktop.
Save numa08/3657968 to your computer and use it in GitHub Desktop.
C# + LINQ でJSONのパースをする ref: http://qiita.com/items/475ab3e8aa9e10441a26
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
namespace ConflimJsonParser
{
public class MyParser
{
private string json = "省略";
public void parse()
{
var str = JObject.Parse(json).SelectToken("response.groups").ToString();
var venues = JArray.Parse(str).SelectMany(groups => groups["items"])
.Select(items => items["venue"]).Select(venue =>
{
var location = venue["location"];
return new Venue()
{
name = (string)venue["name"],
id = (string)venue["id"],
address = (string)location["address"],
crossStreet = (string)location["crossStreet"],
city = (string)location["city"],
state = (string)location["state"],
country = (string)location["country"],
cc = (string)location["cc"],
lat = (double)location["lat"],
lng = (double)location["lng"],
};
});
foreach (var venue in venues)
{
Debug.WriteLine(venue.name);
}
}
}
}
namespace ConflimJsonParser
{
public class Venue
{
public string name { get; set; }
public string address { get; set; }
public string crossStreet { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string cc { get; set; }
public double lat { get; set; }
public double lng { get; set; }
public string id { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment