{
meta: {
code: 200
}
notifications: [
{
type: "notificationTray"
item: {
unreadCount: 0
}
}
]
response: {
venues: [
{
id: "430d0a00f964a5203e271fe3"
name: "Brooklyn Bridge Park"
contact: {
phone: "+12128033822"
formattedPhone: "+1 212-803-3822"
twitter: "nycparks"
facebook: "104475634308"
facebookUsername: "BartowPell"
facebookName: "Bartow-Pell Mansion Museum"
}
location: {
address: "Main St"
crossStreet: "Plymouth St"
lat: 40.70227697066692
lng: -73.9965033531189
distance: 389
postalCode: "11201"
cc: "US"
city: "Brooklyn"
state: "NY"
country: "United States"
formattedAddress: [
"Main St (Plymouth St)"
"Brooklyn, NY 11201"
"United States"
]
}
categories: [
{
id: "4bf58dd8d48988d163941735"
name: "Park"
pluralName: "Parks"
shortName: "Park"
icon: {
prefix: "https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_"
suffix: ".png"
}
primary: true
}
]
verified: true
stats: {
checkinsCount: 28108
usersCount: 17545
tipCount: 171
}
url: "http://nyc.gov/parks"
specials: {
count: 0
items: [ ]
}
hereNow: {
count: 13
summary: "13 people are checked in here"
groups: [
{
type: "others"
name: "Other people here"
count: 13
items: [ ]
}
]
}
referralId: "v-1427653325"
}
{
id: "51eabef6498e10cf3aea7942"
name: "Brooklyn Bridge Park - Pier 2"
contact: { }
location: {
address: "Furman St"
crossStreet: "Brooklyn Bridge Park Greenway"
lat: 40.69956454780675
lng: -73.99835740533105
distance: 146
cc: "US"
city: "Brooklyn"
state: "NY"
country: "United States"
formattedAddress: [
"Furman St (Brooklyn Bridge Park Greenway)"
"Brooklyn, NY"
"United States"
]
}
categories: [
{
id: "4bf58dd8d48988d163941735"
name: "Park"
pluralName: "Parks"
shortName: "Park"
icon: {
prefix: "https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_"
suffix: ".png"
}
primary: true
}
]
verified: false
stats: {
checkinsCount: 1478
usersCount: 1138
tipCount: 10
}
specials: {
count: 0
items: [ ]
}
hereNow: {
count: 1
summary: "One person is checked in here"
groups: [
{
type: "others"
name: "Other people here"
count: 1
items: [ ]
}
]
}
referralId: "v-1427653325"
} ]
confident: true
}
} URI uri = new URI( String.format( "https://api.foursquare.com/v2/venues/search" +
"?ll=%s&v=20140806&m=foursquare&categoryId=4d4b7105d754a06374d81259",
String.format( "%s,%s", latitude, longitude ) ) );
final Configuration build = Configuration.builder().jsonProvider( new JacksonJsonProvider() )
.mappingProvider( new JacksonMappingProvider() ).build();
final Object document = build.jsonProvider().parse( uri.toURL().openConnection().getInputStream(),
Charset.defaultCharset().name() );
final List<Object> list = JsonPath.read( document, "$.response.venues" );
final List<Venue> venues = list.stream().collect( mapping( ( Object i ) -> {
Venue venue = new Venue();
venue.setFoursquareId( JsonPath.read( i, "$.id" ).toString() );
venue.setName( JsonPath.read( i, "$.name" ).toString() );
Location location = new Location();
location.setStreet( JsonPath.read( i, "$.location.address" ).toString() );
location.setCrossStreet( JsonPath.read( i, "$.location.crossStreet" ) );
location.setPostalCode( JsonPath.read( i, "$.location.postalCode" ).toString() );
location.setCity( JsonPath.read( i, "$.location.city" ).toString() );
location.setState( JsonPath.read( i, "$.location.state" ).toString() );
location.setCountry( JsonPath.read( i, "$.location.country" ).toString() );
location.setGeoCode( new GeoCode( "point", new double[]{
JsonPath.read( i, "$.location.lat" ),
JsonPath.read( i, "$.location.lng" )
} ) );
final List<Object> categories = JsonPath.read( i, "$.categories" );
final Optional<Object> categoryJson = categories.stream().findFirst();
if ( categoryJson.isPresent() ) {
venue.setType( JsonPath.read( categoryJson.get(), "$.name" ) );
}
return venue;
}, toList() ) ); final Configuration build = Configuration.builder().options(
Option.DEFAULT_PATH_LEAF_TO_NULL ).jsonProvider( new
JacksonJsonProvider() )
.mappingProvider( new JacksonMappingProvider() ).build();
URI uri = URI.create("https://api.foursquare.com/...");
List<Object> jsonVenues = JsonPath.parse(uri.toURL().openStream()).read("$.response.venues");
List<Venue> venues = jsonVenues.stream().map(o -> {
DocumentContext ctx = JsonPath.parse(o);
String id = ctx.read("$.id", String.class);
String name = ctx.read("$.name", String.class);
return new Venue(id, name, ......);
}).collect(Collectors.toList());URI uri = URI.create("https://api.foursquare.com/...");
List<Venue> venues = JsonPath.parse(uri.toURL().openStream())
.read("$.response.venues", List.class)
.stream()
.map(o -> JsonPath.parse(o).read("$", Venue.class))
.collect(Collectors.toList());
com.jayway.jsonpath.PathNotFoundException: Property ['location'] not found in path $['id']
--
You received this message because you are subscribed to a topic in the Google Groups "JsonPath" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsonpath/yPurMLMbB2Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsonpath+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "JsonPath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonpath+u...@googlegroups.com.
Location location = new Location();
location.setStreet( ctx.read( "$.location.address", String.class ) );
location.setCrossStreet( ctx.read( "$[*].location.crossStreet", String.class ) );
location.setPostalCode( ctx.read( "$.location.postalCode", String.class ) );
location.setCity( ctx.read( "$.location.city", String.class ) );
location.setState( ctx.read( "$.location.state", String.class ) );
location.setCountry( ctx.read( "$.location.country", String.class ) );
final List<Object> list = jsonPath.parse( uri.toURL().openStream() ).read( "$.response.venues" );
final List<Venue> venues = list.stream().collect( mapping( ( o ) -> {
DocumentContext ctx = jsonPath.parse( o );
Venue venue = new Venue();
venue.setFoursquareId( ctx.read( "$.id", String.class ) );
venue.setName( ctx.read( "$.name", String.class ) );
Location location = new Location();
location.setStreet( ctx.read( "$.location.address", String.class ) );
// location.setCrossStreet( ctx.read( "$[*].location.crossStreet", String.class ) );
location.setPostalCode( ctx.read( "$.location.postalCode", String.class ) );
location.setCity( ctx.read( "$.location.city", String.class ) );
location.setState( ctx.read( "$.location.state", String.class ) );
location.setCountry( ctx.read( "$.location.country", String.class ) );
location.setGeoCode( new GeoCode( "Point", new double[]{
ctx.read( "$.location.lng", Double.class ),
ctx.read( "$.location.lat", Double.class )
} ) );
venue.setLocation( location );
final List categories = ctx.read( "$.categories", List.class );
final Optional categoryJson = categories.stream().findFirst();
if ( categoryJson.isPresent() ) {
DocumentContext categoryCtx = jsonPath.parse( categoryJson.get() );
venue.setType( categoryCtx.read( "$.name", String.class ) );
}
return venue;
}, toList() ) );
Thanks for your attention!Anderson Vaz