Querying field value in MongoDB Document - java

I have a document embedded in another document. I am able to get the values of the parent but not the inner document. (The commented line gives an error). Below is the code.
DB db = mongoClient.getDB("events");
DBCollection coll = db.getCollection("usercomment");
BasicDBObject searchQuery = new BasicDBObject("source", "twitter").append("data.id_str", "641400902545024");
DBCursor cursor = coll.find(searchQuery);
while(cursor.hasNext()) {
DBObject currDocument = cursor.next();
BasicDBObject newDocument = new BasicDBObject("data", currDocument.get("data"));
//System.out.println(currDocument.get("data.user.location").toString());
System.out.println(currDocument.get("companyName").toString());
}
Below is the json as in Mongo (value of currDocument that I get in Debug):
{
"_id": {
"$oid": "55eff71de4b0b91376cb5920"
},
"createdDate": {
"$date": "2015-09-09T00:01:06.000Z"
},
"username": "Bubble",
"userMessage": "Hello from #Iowa.\",
"entities": {
"symbols": [],
"urls": [],
"hashtags": [{
"text": "Iowa",
"indices": [23,
28]
},
{
"text": "WFHM",
"indices": [48,
53]
},
{
"text": "twitter",
"indices": [69,
77]
}],
"media": [{
"id": 641400900641140736,
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
},
"media_url_https": "https://pbs.twimg.com/media/COaAxg_p.jpg",
"media_url": "http://pbs.twimg.com/media/UsAAxg_p.jpg",
"expanded_url": "http://twitter.com/Bubble/status/64140024/photo/1",
"indices": [88,
110],
"id_str": "6414009140736",
"display_url": "pic.twitter.com/ErB8Ed8if",
"type": "photo",
"url": "http://t.co/rB8Ed8if"
}],
"user_mentions": [{
"id": 1178011,
"name": "XXX",
"indices": [0,
11],
"screen_name": "XXX",
"id_str": "1178011"
}]
},
"userImage": "http://pbs.twimg.com/profile_images/542698316577/Jvx7sIr_normal.jpeg",
"feedLink": "https://www.twitter.com/statuses/6414009085024",
"feed_id": "64140541185024",
"inReplyTo": "null",
"timestamp": "146866000",
"source": "twitter",
"contactName": "###",
"postCat": "post",
"collection": "usercomment",
"messageId": "1400902541185024",
"companyName": "XXX",
"type": "citation",
"data": {
"retweeted": false,
"in_reply_to_screen_name": "XXX",
"possibly_sensitive": false,
"lang": "en",
"in_reply_to_status_id_str": null,
"id": 6414009025185024,
"in_reply_to_user_id_str": "1178011",
"in_reply_to_status_id": null,
"created_at": "Wed Sep 11 00:01:06 +0000 2015",
"favorite_count": 1,
"place": {
"id": "1c67f9d9ae7f69",
"bounding_box": {
"type": "Polygon",
"coordinates": [[[-93.709504,
41.49702],
[-93.503235,
[-93.503235,
41.6514656],
[-93.709504,
41.6514656]]]
},
"place_type": "city",
"contained_within": [],
"name": "DesMoines",
"attributes": {
},
"country_code": "US",
"url": "https://api.twitter.com/1.1/geo/id/1c6ae7f69.json",
"country": "United States",
"full_name": "Des Moines, IA"
},
"coordinates": null,
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"geo": null,
"is_quote_status": false,
"source": "Twitter Web Client",
"favorited": false,
"in_reply_to_user_id": 1178011,
"retweet_count": 0,
"id_str": "641400902541185024",
"user": {
"location": "Des Moines, Iowa",
"default_profile": false,
"profile_background_tile": false,
"statuses_count": 3721,
"lang": "en",
"profile_link_color": "B37700",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/60056624/14246371",
"id": 60054624,
"following": false,
"protected": false,
"favourites_count": 200,
"profile_text_color": "3333",
"description": "Inventor thinkORANGE(™), eteran",
"verified": false,
"contributors_enabled": false,
"profile_sidebar_border_color": "C0DED",
"name": "Robert Res, Jr",
"profile_background_color": "C0DED",
"created_at": "Tue Jun 05 22:17:22 +0000 2012",
"is_translation_enabled": false,
"default_profile_image": false,
"followers_count": 1615,
"has_extended_profile": false,
"profile_image_url_https": "https://pbs.twimg.com/profile_images/54269577/Jvx79sIr_normal.jpeg",
"geo_enabled": true,
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/b.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/thee1/bg.png",
"follow_request_sent": false,
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [{
"expanded_url": "http://about.me/bob.jr",
"indices": [0,
22],
"display_url": "about.me/bob.rjr",
"url": "http://t.co/rLVnPn"
}]
}
},
"url": "http://t.co/ryRnPn",
"utc_offset": null,
"time_zone": null,
"notifications": false,
"profile_use_background_image": true,
"friends_count": 1770,
"profile_sidebar_fill_color": "DDF6",
"screen_name": "BubbleWormBob",
"id_str": "600546624",
"profile_image_url": "http://pbs.twimg.com/profile_images/54269837/Jvx79rmal.jpeg",
"listed_count": 27,
"is_translator": false,
"state": "IA"
}
},
"sentimentUpdated": "Y",
"profileUpdated": "Y",
"feedLoadDate": "20160205924",
"kafkaoffset": "2075805-2",
"sentiment": "Positive",
"posWords": ["great"],
"negWords": [],
"ner": {
"per": [],
"org": [],
"loc": [],
"oth": ["http:\\/\\/t.co\\/EGrB8E8if"]
},
"kloudid": "534802137717",
"kscore": "54.086",
"kbucket": "50-59",
"kscoredaychange": -0.05502,
"kscoreweekchange": 1.255317743,
"kscoremonthchange": 5.7708270082,
"kinfluencerscount": 5,
"kinfluenceescount": 5,
"ktopics": ",Leadership,Patement,India,",
"rtCount": 0,
"replyCount": 0,
"engCount": 0,
"mediaType": "image",
"mediaURL": "http://pbs.twimg.com/media/COa2g_p.jpg"
}
How to get the field values from the nested jsons here?

Have you tried pulling each node one by one as it follows.
I suppose you want to get "data.user.location"
BasicDBObject newDocument = new BasicDBObject("data", currDocument.get("data"));
System.out.println(((DBObject)newDocument.get("data")).get("location"));

Related

Obtaining a specific field in Elastic search using Kibana and Java

I am very new to ELK stack. I am trying to retrieve a specific field (like in MySQL think we have a table called "Users", trying to retrieve the "phoneNumber" column). I am in need of doing that using Java as well as using the queries typed in Kibana. (for example lets think we need to retrieve the field comments in the elastic search database) Thank you for the help. I am new to Stack Overflow. So if I have done something wrong in asking the question, please let me know, ill correct it. Following is the result obtained in kibana by typing,
POST local_rs_4_0_0_app_test_1552993787904/_search
{
"query": {
"match_all": {}
}
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"failed": 0
},
"hits": {
"total": 16,
"max_score": 1,
"hits": [
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "reviewmodel",
"_id": "rm_apptest1552993787904_hotel",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"appKey": "app_test_1552993787904",
"entityType": "hotel",
"reviewParameters": {
"0": {
"key": "title",
"description": "Title",
"writeEnabled": true,
"readEnabled": true,
"usedAsMetadata": false
},
"1": {
"key": "overall",
"description": "Overall",
"writeEnabled": true,
"readEnabled": true,
"usedAsMetadata": false
},
"2": {
"key": "comment",
"description": "Comment",
"writeEnabled": true,
"readEnabled": true,
"usedAsMetadata": false
},
"3": {
"key": "country",
"description": "Country",
"writeEnabled": true,
"readEnabled": true,
"usedAsMetadata": true
}
},
"supportedOntoClass": "hotel"
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "formtemplate",
"_id": "AWmVrLRfjVbLQiy9v6fG",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "ft_apptest1552993787904_hotel_hotelcopy1",
"templateName": "hotel Copy 1",
"createdUser": "usr_2012187654",
"createdTime": 1552994317403,
"formDescription": "",
"thankYouNote": "Thank You",
"formHeaderImage": "",
"lastModifiedUser": "usr_2012187654",
"lastModifiedTime": 1552994349085,
"appKey": "app_test_1552993787904",
"entityType": "hotel",
"apiCall": null,
"entityMappedApiCall": null,
"embeddableScript": null,
"deleted": true,
"defaultFormTemplate": false,
"defaultAttachableFormTemplate": false,
"mappedViewTemplateKey": "vt_apptest1552993787904_hotel_hotelcopy1",
"components": {
"0": {
"cmpId": "title1552994317403",
"component": "TEXT_FIELD",
"parameterKey": "title",
"required": true,
"label": "Review Title",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"1": {
"cmpId": "overall1552994317403",
"component": "STAR_INPUT",
"parameterKey": "overall",
"required": true,
"label": "Overall Rating",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"2": {
"cmpId": "comment1552994317403",
"component": "TEXT_AREA",
"parameterKey": "comment",
"required": true,
"label": "Comment",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"3": {
"cmpId": "country1552994317403",
"component": "COUNTRY_PICKER",
"parameterKey": "country",
"required": false,
"label": "Country",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
}
},
"embeddedEntities": [],
"groups": []
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "viewtemplate",
"_id": "AWmVrLTZjVbLQiy9v6fH",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "vt_apptest1552993787904_hotel_hotelcopy1",
"templateName": "hotel Copy 1",
"appKey": "app_reviewspotter_1552993787904",
"entityType": "hotel",
"createdUser": "usr_2012187654",
"createdTime": 1552994317527,
"lastModifiedUser": "usr_2012187654",
"lastModifiedTime": 1552994349270,
"components": {
"0": {
"parameterKey": "title",
"component": "TEXT_VIEW",
"label": "Review Title",
"publicViewVisible": true
},
"1": {
"parameterKey": "overall",
"component": "STAR_VIEW",
"label": "Overall Rating",
"publicViewVisible": true
},
"2": {
"parameterKey": "comment",
"component": "TEXT_VIEW",
"label": "Comment",
"publicViewVisible": true
},
"3": {
"parameterKey": "country",
"component": "TEXT_VIEW",
"label": "Country",
"publicViewVisible": true
}
},
"editTemplateId": "ft_apptest1552993787904_hotel_hotelcopy1",
"replyEnabled": true,
"editEnabled": true,
"deleteEnabled": true,
"voteEnabled": true,
"socialShareEnabled": false,
"apiCall": null,
"embeddableScript": null,
"deleted": true,
"defaultViewTemplate": false
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "conversation",
"_id": "cnv_apptest1552993787904_tour__Anuradhapura__1552994436382",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"conversationId": "cnv_apptest1552993787904_tour__Anuradhapura__1552994436382",
"title": "UPDATES",
"startedBy": "usr_2012187654",
"startedByDisplayName": "F",
"startedAt": 1552994436382,
"closedBy": null,
"closedByDisplayName": null,
"closedAt": 0,
"lastUpdatedAt": 1552994436382,
"status": "ONGOING",
"conversationType": "UPDATES",
"startedFromType": "GENERAL",
"priorityLevel": "MEDIUM",
"markedAsIncident": false,
"incidentStatus": "NOT_APPLICABLE",
"appKey": "app_test_1552993787904",
"entityType": "tour",
"entityId": "Anuradhapura",
"groupKey": null,
"limitedToShared": false,
"sharedUserIds": [],
"deleted": false
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "formtemplate",
"_id": "AWmVrobwjVbLQiy9v6fI",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "ft_apptest1552993787904_tour_tour",
"templateName": "tour",
"createdUser": "usr_2012187654",
"createdTime": 1552994436841,
"formDescription": "",
"thankYouNote": "Thank You",
"formHeaderImage": "",
"lastModifiedUser": null,
"lastModifiedTime": null,
"appKey": "app_test_1552993787904",
"entityType": "tour",
"apiCall": null,
"entityMappedApiCall": null,
"embeddableScript": null,
"deleted": false,
"defaultFormTemplate": true,
"defaultAttachableFormTemplate": false,
"mappedViewTemplateKey": "vt_apptest1552993787904_tour_tour",
"components": {
"0": {
"cmpId": "title1552994436841",
"component": "TEXT_FIELD",
"parameterKey": "title",
"required": true,
"label": "Review Title",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"1": {
"cmpId": "overall1552994436841",
"component": "STAR_INPUT",
"parameterKey": "overall",
"required": true,
"label": "Overall Rating",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"2": {
"cmpId": "comment1552994436841",
"component": "TEXT_AREA",
"parameterKey": "comment",
"required": true,
"label": "Comment",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
},
"3": {
"cmpId": "country1552994436841",
"component": "COUNTRY_PICKER",
"parameterKey": "country",
"required": false,
"label": "Country",
"description": null,
"attributes": [],
"options": [],
"publicViewVisible": true
}
},
"embeddedEntities": [],
"groups": []
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "review",
"_id": "r_anuradhapura_1552994866938",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"reviewId": "r_anuradhapura_1552994866938",
"version": 1,
"status": "APPROVED",
"deleted": false,
"readyToProcess": true,
"appKey": "app_test_1552993787904",
"appName": "test",
"createdUser": "anonymous-user#app_test_1552993787904.com",
"displayName": "Oshana",
"createdTime": 1552994866943,
"entityType": "tour",
"entityId": "Anuradhapura",
"entityName": "Anuradhapura",
"comment": "Test Comment",
"title": "Test",
"parentReview": null,
"childReviews": [],
"numberData": [
{
"key": "overall",
"value": 5
}
],
"textData": [],
"imageData": [],
"numberMeta": [],
"textMeta": [
{
"key": "user-agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
},
{
"key": "ip",
"value": "0:0:0:0:0:0:0:1"
},
{
"key": "source",
"value": "DIRECT"
},
{
"key": "country",
"value": "Russia"
}
],
"replies": [],
"sentiments": [],
"scoredComment": [],
"rawNumberData": {
"overall": 5
},
"rawTextMeta": {
"country": "Russia",
"ip": "0:0:0:0:0:0:0:1",
"source": "DIRECT",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
},
"rawNumberMeta": {},
"rawScoredComment": {},
"pvCount": 0,
"nvCount": 0
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "viewtemplate",
"_id": "AWmVq7_-jVbLQiy9v6fD",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "vt_apptest1552993787904_hotel_hotel",
"templateName": "hotel",
"appKey": "app_test_1552993787904",
"entityType": "hotel",
"createdUser": "usr_2012187654",
"createdTime": 1552994254811,
"lastModifiedUser": null,
"lastModifiedTime": null,
"components": {
"0": {
"parameterKey": "title",
"component": "TEXT_VIEW",
"label": "Review Title",
"publicViewVisible": true
},
"1": {
"parameterKey": "overall",
"component": "STAR_VIEW",
"label": "Overall Rating",
"publicViewVisible": true
},
"2": {
"parameterKey": "comment",
"component": "TEXT_VIEW",
"label": "Comment",
"publicViewVisible": true
},
"3": {
"parameterKey": "country",
"component": "TEXT_VIEW",
"label": "Country",
"publicViewVisible": true
}
},
"editTemplateId": "ft_apptest1552993787904_hotel_hotel",
"replyEnabled": true,
"editEnabled": true,
"deleteEnabled": true,
"voteEnabled": true,
"socialShareEnabled": false,
"apiCall": null,
"embeddableScript": null,
"deleted": false,
"defaultViewTemplate": true
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "viewtemplate",
"_id": "AWmVq8LejVbLQiy9v6fF",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "vt_apptest1552993787904_hotel_hotelsubform",
"templateName": "hotel Sub Form",
"appKey": "app_test_1552993787904",
"entityType": "hotel",
"createdUser": "usr_2012187654",
"createdTime": 1552994255578,
"lastModifiedUser": null,
"lastModifiedTime": null,
"components": {
"0": {
"parameterKey": "title",
"component": "TEXT_VIEW",
"label": "Review Title",
"publicViewVisible": true
},
"1": {
"parameterKey": "overall",
"component": "STAR_VIEW",
"label": "Overall Rating",
"publicViewVisible": true
},
"2": {
"parameterKey": "comment",
"component": "TEXT_VIEW",
"label": "Comment",
"publicViewVisible": true
}
},
"editTemplateId": "ft_apptest1552993787904_hotel_hotelsubform",
"replyEnabled": true,
"editEnabled": true,
"deleteEnabled": true,
"voteEnabled": true,
"socialShareEnabled": false,
"apiCall": null,
"embeddableScript": null,
"deleted": false,
"defaultViewTemplate": false
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "viewtemplate",
"_id": "AWmVron1jVbLQiy9v6fL",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"templateId": "vt_apptest1552993787904_tour_toursubform",
"templateName": "tour Sub Form",
"appKey": "app_test_1552993787904",
"entityType": "tour",
"createdUser": "usr_2012187654",
"createdTime": 1552994437618,
"lastModifiedUser": null,
"lastModifiedTime": null,
"components": {
"0": {
"parameterKey": "title",
"component": "TEXT_VIEW",
"label": "Review Title",
"publicViewVisible": true
},
"1": {
"parameterKey": "overall",
"component": "STAR_VIEW",
"label": "Overall Rating",
"publicViewVisible": true
},
"2": {
"parameterKey": "comment",
"component": "TEXT_VIEW",
"label": "Comment",
"publicViewVisible": true
}
},
"editTemplateId": "ft_apptest1552993787904_tour_toursubform",
"replyEnabled": true,
"editEnabled": true,
"deleteEnabled": true,
"voteEnabled": true,
"socialShareEnabled": false,
"apiCall": null,
"embeddableScript": null,
"deleted": false,
"defaultViewTemplate": false
}
},
{
"_index": "local_rs_4_0_0_app_test_1552993787904",
"_type": "review",
"_id": "r_anuradhapura_1552994964151",
"_score": 1,
"_source": {
"modelVersion": "RS_4_0_0",
"reviewId": "r_anuradhapura_1552994964151",
"version": 1,
"status": "APPROVED",
"deleted": false,
"readyToProcess": true,
"appKey": "app_test_1552993787904",
"appName": "test",
"createdUser": "anonymous-user#app_test_1552993787904.com",
"displayName": "Oshana-1",
"createdTime": 1552994964158,
"entityType": "tour",
"entityId": "Anuradhapura",
"entityName": "Anuradhapura",
"comment": "Test",
"title": "Test-2",
"parentReview": null,
"childReviews": [],
"numberData": [
{
"key": "overall",
"value": 5
}
],
"textData": [],
"imageData": [],
"numberMeta": [],
"textMeta": [
{
"key": "user-agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
},
{
"key": "ip",
"value": "0:0:0:0:0:0:0:1"
},
{
"key": "source",
"value": "DIRECT"
},
{
"key": "country",
"value": "Afghanistan"
}
],
"replies": [],
"sentiments": [],
"scoredComment": [],
"rawNumberData": {
"overall": 5
},
"rawTextMeta": {
"country": "Afghanistan",
"ip": "0:0:0:0:0:0:0:1",
"source": "DIRECT",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
},
"rawNumberMeta": {},
"rawScoredComment": {},
"pvCount": 0,
"nvCount": 0
}
}
]
}
}
when you want to return just some specific stuff, your elasticsearch query should contain "_source" : "[fields you desire]" https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

ElasticSearch: query a deep date field using an hours-range filter independent date

How can I query all the advert using the field
("group": { "times": [{"startTime", "startTime"}]})
no matter the date is, query is base on hours-range.
My index is like (for example "startTime": "2016-12-13T09:00:00+08:00",
"endTime": "2016-12-13T22:00:00+08:00", but I just care about the "09:00:00" and "22:00:00"):
{
"_index": "advert",
"_type": "advert",
"_id": "6217903907666941952",
"_score": 7.730222,
"_source": {
"id": "6217903907666941952",
"promotionUrl": "http://www.baidu.com",
"summary": "test",
"user": {
"createdBy": "ag-kf",
"createdDate": "2016-12-05T11:48:52+08:00",
"lastModifiedBy": "admin",
"lastModifiedDate": "2016-12-13T14:10:52+08:00",
"id": "6211385611895442432",
"login": "ag-ggz02",
"email": "testing0000019#21cn.com",
"region": null,
"activated": true,
"locked": false,
"langKey": "zh-cn"
},
"group": {
"createdBy": "ag-ggz02",
"id": "6214281669688469248",
"name": "AGggz002推广测试02",
"dailyLimit": 500,
"deliveryChannelsLimit": 5,
"startDate": "2017-01-12T00:00:00+08:00",
"endDate": "2017-01-19T00:00:00+08:00",
"paymentMode": "CPC",
"deliveryMode": "SPEEDUP",
"status": "VALID",
"times": [
{
"createdBy": "ag-ggz02",
"createdDate": "2017-01-12T14:40:59+08:00",
"lastModifiedBy": "ag-ggz02",
"lastModifiedDate": "2017-01-12T14:40:59+08:00",
"id": "6225199665533659392",
"startTime": "2016-12-13T09:00:00+08:00",
"endTime": "2016-12-13T22:00:00+08:00"
}
]
}
}}

Category Search using Foursquare returns wrong Category

I'm doing a category search for food but I'm getting things like Bridges back. Can somebody please verify I'm structuring the URL correctly and if so, possibly point out what I'm doing wrong?
Thank you so much in advance.
URL (blocked out the sensitive stuff like client id and secret):
https://api.foursquare.com/v2/venues/search?client_id=PUT_YOUR_CLIENT_ID_HERE&client_secret=PUT_YOUR_CLIENT_SECRET_HERE&v=20140714&ll=40.7,-74&radius=1000&category=4d4b7105d754a06374d81259
The category ID I'm using is from foursquare's website. It's the ID for 'Food'
You can see the list of IDs Right Here
Here's my response in json (edited for size):
{
"meta": {
"code": 200
},
"response": {
"venues": [
{
"id": "430d0a00f964a5203e271fe3",
"name": "Brooklyn Bridge Park",
"contact": {
"phone": "2128033822",
"formattedPhone": "(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": 28131,
"usersCount": 17548,
"tipCount": 177
},
"url": "http:\/\/nyc.gov\/parks",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 15,
"summary": "15 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 15,
"items": [
]
}
]
},
"referralId": "v-1429381004"
},
{
"id": "4a43bcb7f964a520bba61fe3",
"name": "Brooklyn Bridge",
"contact": {
"twitter": "nyc_dot",
"facebook": "166279802886",
"facebookUsername": "NYCDOT",
"facebookName": "NYC DOT"
},
"location": {
"address": "Brooklyn Bridge",
"lat": 40.705953265881305,
"lng": -73.99656772613525,
"distance": 723,
"postalCode": "10038",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn Bridge",
"New York, NY 10038",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1df941735",
"name": "Bridge",
"pluralName": "Bridges",
"shortName": "Bridge",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/bridge_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 120787,
"usersCount": 67456,
"tipCount": 534
},
"url": "http:\/\/www.nyc.gov\/dot",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 18,
"summary": "18 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 18,
"items": [
]
}
]
},
"storeId": "",
"referralId": "v-1429381004"
},
{
"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": 1508,
"usersCount": 1161,
"tipCount": 10
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "3fd66200f964a520daf11ee3",
"name": "South Street Seaport",
"contact": {
"phone": "2127327678",
"formattedPhone": "(212) 732-7678",
"twitter": "theseaport"
},
"location": {
"address": "South St",
"crossStreet": "Pier 17",
"lat": 40.70566047104496,
"lng": -74.00287628173828,
"distance": 675,
"postalCode": "10038",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"South St (Pier 17)",
"New York, NY 10038",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1e0941735",
"name": "Harbor \/ Marina",
"pluralName": "Harbors \/ Marinas",
"shortName": "Harbor \/ Marina",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/harbor_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 45850,
"usersCount": 29726,
"tipCount": 180
},
"url": "http:\/\/www.southstreetseaport.com",
"specials": {
"count": 0,
"items": [
]
},
"events": {
"count": 1,
"summary": "Hornblower",
"items": [
{
"id": "550a2152498e6adfd409dfa4",
"name": "Hornblower",
"categories": [
],
"allDay": true,
"date": 1429345800,
"timeZone": "America\/New_York",
"text": "",
"url": "http:\/\/www.voiceplaces.com\/new-york\/hornblower-4897577-e",
"images": [
],
"provider": {
"name": "Village Voice",
"iconUrl": {
"prefix": "https:\/\/playfoursquare.s3.amazonaws.com\/events\/images\/partners\/villagevoice\/",
"sizes": [
20,
40
],
"name": "\/logo.png"
},
"urlText": "more info"
},
"stats": {
"checkinsCount": 0,
"usersCount": 0
}
}
]
},
"hereNow": {
"count": 5,
"summary": "5 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 5,
"items": [
]
}
]
},
"venuePage": {
"id": "59071427"
},
"storeId": "",
"referralId": "v-1429381004"
},
{
"id": "42377700f964a52024201fe3",
"name": "Brooklyn Heights Promenade",
"contact": {
},
"location": {
"address": "Columbia Heights",
"crossStreet": "btwn Remsen & Orange",
"lat": 40.69829137715981,
"lng": -73.99663209915161,
"distance": 342,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Columbia Heights (btwn Remsen & Orange)",
"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": false,
"stats": {
"checkinsCount": 18073,
"usersCount": 8755,
"tipCount": 138
},
"url": "http:\/\/nyharborparks.org\/visit\/brhe.html",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "53ff2935498e161412b3e871",
"name": "Brooklyn Bridge Park - Pier 2 Yoga Court",
"contact": {
},
"location": {
"lat": 40.700111,
"lng": -73.999185,
"distance": 69,
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn, NY",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d102941735",
"name": "Yoga Studio",
"pluralName": "Yoga Studios",
"shortName": "Yoga Studio",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/shops\/gym_yogastudio_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 6,
"usersCount": 3,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4f2c1bbae4b0ccfb1d99b510",
"name": "kk hair salon",
"contact": {
},
"location": {
"lat": 40.69956588745117,
"lng": -74.00108337402344,
"distance": 103,
"cc": "US",
"state": "New York",
"country": "United States",
"formattedAddress": [
"New York",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d110951735",
"name": "Salon \/ Barbershop",
"pluralName": "Salons \/ Barbershops",
"shortName": "Salon \/ Barbershop",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/shops\/salon_barber_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1,
"usersCount": 1,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "540ca09f498e9d0f44e40791",
"name": "Smorgasburg at Brooklyn Bridge Park - Pier 2",
"contact": {
"twitter": "bkflea"
},
"location": {
"address": "Pier 2 (at Brooklyn Bridge Park)",
"lat": 40.69938593942123,
"lng": -73.99699733176632,
"distance": 262,
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Pier 2 (at Brooklyn Bridge Park)",
"Brooklyn, NY",
"United States"
]
},
"categories": [
{
"id": "53e0feef498e5aac066fd8a9",
"name": "Street Food Gathering",
"pluralName": "Street Food Gatherings",
"shortName": "Street Food Gathering",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/streetfood_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 545,
"usersCount": 523,
"tipCount": 6
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "3fd66200f964a520e9e81ee3",
"name": "Grimaldi's Pizzeria",
"contact": {
"phone": "7188584300",
"formattedPhone": "(718) 858-4300",
"twitter": "grimaldisnyc"
},
"location": {
"address": "1 Front St",
"crossStreet": "at Cadman Plaza W",
"lat": 40.70250515261926,
"lng": -73.9933359887217,
"distance": 627,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"1 Front St (at Cadman Plaza W)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1ca941735",
"name": "Pizza Place",
"pluralName": "Pizza Places",
"shortName": "Pizza",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/pizza_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 21973,
"usersCount": 18381,
"tipCount": 459
},
"url": "http:\/\/www.grimaldis.com",
"hasMenu": true,
"menu": {
"type": "Menu",
"label": "Menu",
"anchor": "View Menu",
"url": "https:\/\/foursquare.com\/v\/grimaldis-pizzeria\/3fd66200f964a520e9e81ee3\/menu",
"mobileUrl": "https:\/\/foursquare.com\/v\/3fd66200f964a520e9e81ee3\/device_menu"
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4c34a57da0ced13a9379186e",
"name": "Under The Brooklyn Bridge",
"contact": {
"twitter": "nyc_dot",
"facebook": "166279802886",
"facebookUsername": "NYCDOT",
"facebookName": "NYC DOT"
},
"location": {
"address": "Brooklyn Bridge",
"crossStreet": "FDR Dr",
"lat": 40.703475724581324,
"lng": -73.99405334200495,
"distance": 633,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn Bridge (FDR Dr)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d165941735",
"name": "Scenic Lookout",
"pluralName": "Scenic Lookouts",
"shortName": "Scenic Lookout",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/sceniclookout_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 7406,
"usersCount": 5831,
"tipCount": 31
},
"url": "http:\/\/www.nyc.gov\/dot",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4cb92bdc7148f04d9336d5ab",
"name": "Livys apartment !",
"contact": {
},
"location": {
"address": "95 Wall St",
"crossStreet": "Water st",
"lat": 40.700249,
"lng": -74.001442,
"distance": 124,
"postalCode": "10005",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"95 Wall St (Water st)",
"New York, NY 10005",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1a3941735",
"name": "College Residence Hall",
"pluralName": "College Residence Halls",
"shortName": "Residence Hall",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/education\/residencehall_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1,
"usersCount": 1,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4c5435bf4623be9a62ee66f2",
"name": "Brooklyn Bridge Park - Pier 4",
"contact": {
},
"location": {
"address": "214 Furman St",
"crossStreet": "Montague St",
"lat": 40.69662731765942,
"lng": -73.99846644034649,
"distance": 397,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"214 Furman St (Montague 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": false,
"stats": {
"checkinsCount": 1196,
"usersCount": 945,
"tipCount": 3
},
"url": "http:\/\/www.brooklynbridgepark.org\/the-park\/future-park\/pier-4",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "5054eb43e4b04ed4f0dd1b30",
"name": "La cabana",
"contact": {
},
"location": {
"lat": 40.69875,
"lng": -73.99953,
"distance": 144,
"cc": "US",
"state": "New York",
"country": "United States",
"formattedAddress": [
"New York",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d154941735",
"name": "Cuban Restaurant",
"pluralName": "Cuban Restaurants",
"shortName": "Cuban",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/cuban_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 4,
"usersCount": 4,
"tipCount": 1
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4ae62580f964a52011a521e3",
"name": "Danish Seamen's Church",
"contact": {
},
"location": {
"address": "102 Willow St",
"lat": 40.698023159650134,
"lng": -73.99568889745463,
"distance": 425,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"102 Willow St",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d132941735",
"name": "Church",
"pluralName": "Churches",
"shortName": "Church",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/building\/religious_church_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 106,
"usersCount": 71,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
}
],
"confident": true
}
}
Please check foursquare venues search parameters correctly, you used "category" parameter but the correct parameter is "categoryId" (not categoryid). So you should change your url to:
https://api.foursquare.com/v2/venues/search?client_id=PUT_YOUR_CLIENT_ID_HERE&client_secret=PUT_YOUR_CLIENT_SECRET_HERE&v=20140714&ll=40.7,-74&radius=1000&categoryId=4d4b7105d754a06374d81259

GSON and Google Drive Java API - “Expected BEGIN_OBJECT but was BEGIN_ARRAY”?

I am trying to serialize and deserialize this FileList object by using Gson. The classes can be found from here:
https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/FileList.html
and
https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/File.html
This is how I'm doing it:
private List<File> mListOfResults = new ArrayList<File>();
FileList fileList = new FileList();
fileList.setItems(mListOfResults);
outState.putString("RESULT_LIST", new Gson().toJson(fileList));
and this is how I'm trying to unserialize it:
Type collectionType = new TypeToken<FileList>(){}.getType();
FileList fileList = new Gson().fromJson(savedInstanceState.getString("RESULT_LIST"), collectionType);
Here's the JSON:
{
"items": [
{
"alternateLink": "censoredLink",
"appDataContents": false,
"copyable": true,
"createdDate": {
"value": 1414937347638,
"tzShift": 0,
"dateOnly": false
},
"downloadUrl": "censoredUrl",
"editable": true,
"etag": "\"M4lMw\"",
"fileExtension": "png",
"fileSize": 982646,
"headRevisionId": "0BPQ",
"iconLink": "url",
"id": "0BxWW1fYlE",
"imageMediaMetadata": {
"height": 1920,
"width": 1200
},
"kind": "drive#file",
"labels": {
"hidden": false,
"restricted": false,
"starred": false,
"trashed": false,
"viewed": true
},
"lastModifyingUser": {
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "myId"
},
"lastModifyingUserName": "myName",
"lastViewedByMeDate": {
"value": 1415793202783,
"tzShift": 0,
"dateOnly": false
},
"markedViewedByMeDate": {
"value": 1414937361409,
"tzShift": 0,
"dateOnly": false
},
"md5Checksum": "myMd5Checksum",
"mimeType": "image\/png",
"modifiedByMeDate": {
"value": 1415793202783,
"tzShift": 0,
"dateOnly": false
},
"modifiedDate": {
"value": 1415793202783,
"tzShift": 0,
"dateOnly": false
},
"originalFilename": "Screenshot_2014-11-02-16-07-03.png",
"ownerNames": [
"myName"
],
"owners": [
{
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "myId"
}
],
"parents": [
{
"id": "parentId",
"isRoot": true,
"kind": "drive#parentReference",
"parentLink": "parentLink",
"selfLink": "mySelfLink"
}
],
"quotaBytesUsed": 982646,
"selfLink": "Link",
"shared": false,
"thumbnailLink": "Link",
"title": "Screenshot_2014-11-02-16-07-03.png",
"userPermission": {
"etag": "\"M4l5R3cU\"",
"id": "me",
"kind": "drive#permission",
"role": "owner",
"selfLink": "myLink",
"type": "user"
},
"version": 20986,
"webContentLink": "myWebContentLink",
"writersCanShare": true
},
{
"alternateLink": "myAlternateLink",
"appDataContents": false,
"copyable": true,
"createdDate": {
"value": 1412844742040,
"tzShift": 0,
"dateOnly": false
},
"downloadUrl": "myDownloadUrl",
"editable": true,
"etag": "\"MDc0MQ\"",
"fileExtension": "png",
"fileSize": 743314,
"headRevisionId": "0Bx",
"iconLink": "myLink",
"id": "myId",
"imageMediaMetadata": {
"height": 814,
"width": 609
},
"kind": "drive#file",
"labels": {
"hidden": false,
"restricted": false,
"starred": false,
"trashed": false,
"viewed": true
},
"lastModifyingUser": {
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "02323"
},
"lastModifyingUserName": "myName",
"lastViewedByMeDate": {
"value": 1415605118741,
"tzShift": 0,
"dateOnly": false
},
"markedViewedByMeDate": {
"value": 1412844842132,
"tzShift": 0,
"dateOnly": false
},
"md5Checksum": "23123",
"mimeType": "image\/png",
"modifiedByMeDate": {
"value": 1415605118741,
"tzShift": 0,
"dateOnly": false
},
"modifiedDate": {
"value": 1415605118741,
"tzShift": 0,
"dateOnly": false
},
"originalFilename": "puasdgessy.png",
"ownerNames": [
"myName"
],
"owners": [
{
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "23123"
}
],
"parents": [
{
"id": "parentId",
"isRoot": true,
"kind": "drive#parentReference",
"parentLink": "myParentLink",
"selfLink": "mySelfLink"
}
],
"quotaBytesUsed": 743314,
"selfLink": "mySelfLink",
"shared": false,
"thumbnailLink": "myThumbnailLink",
"title": "asd.png",
"userPermission": {
"etag": "\"M-7E\"",
"id": "me",
"kind": "drive#permission",
"role": "owner",
"selfLink": "myLink",
"type": "user"
},
"version": 20928,
"webContentLink": "myLink,
"writersCanShare": true
},
{
"alternateLink": "myAlternateLink",
"appDataContents": false,
"copyable": true,
"createdDate": {
"value": 1414836963515,
"tzShift": 0,
"dateOnly": false
},
"downloadUrl": "myDownloadUrl",
"editable": true,
"etag": "\"M4MA\"",
"fileExtension": "png",
"fileSize": 48876,
"headRevisionId": "myId",
"iconLink": "myIcon",
"id": "myId",
"imageMediaMetadata": {
"height": 1920,
"width": 1200
},
"kind": "drive#file",
"labels": {
"hidden": false,
"restricted": false,
"starred": false,
"trashed": false,
"viewed": true
},
"lastModifyingUser": {
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "061"
},
"lastModifyingUserName": "myName",
"lastViewedByMeDate": {
"value": 1415605116280,
"tzShift": 0,
"dateOnly": false
},
"markedViewedByMeDate": {
"value": 1414937348615,
"tzShift": 0,
"dateOnly": false
},
"md5Checksum": "e29d",
"mimeType": "image\/png",
"modifiedByMeDate": {
"value": 1415605116280,
"tzShift": 0,
"dateOnly": false
},
"modifiedDate": {
"value": 1415605116280,
"tzShift": 0,
"dateOnly": false
},
"originalFilename": "Screenshot_2014-11-01-12-15-27.png",
"ownerNames": [
"myName"
],
"owners": [
{
"displayName": "myName",
"emailAddress": "myEmail",
"isAuthenticatedUser": true,
"kind": "drive#user",
"permissionId": "myPermissionId"
}
],
"parents": [
{
"id": "myId",
"isRoot": true,
"kind": "drive#parentReference",
"parentLink": "myParentLink",
"selfLink": "mySelfLink"
}
],
"quotaBytesUsed": 48876,
"selfLink": "mySelfLink",
"shared": false,
"thumbnailLink": "myThumbnailLink",
"title": "Scree5-27.png",
"userPermission": {
"etag": "\"M4RZpXxU\"",
"id": "me",
"kind": "drive#permission",
"role": "owner",
"selfLink": "myLink",
"type": "user"
},
"version": 20927,
"webContentLink": "myWebContentLink",
"writersCanShare": true
}
]
}
I could really use some help with this, as I've been stuck with this problem for 2-3 weeks with my school colleague.
EDIT: I managed to serialize and deserialize FileList object, but now a new problem occurs when I try to get a specific File from deserialized FileList. The serialisation works if I don't add FileList's items to a List. Below is the error that I'm receiving.
Caused by: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.google.api.services.drive.model.File
Thanks a lot for your time.

Android/Java Parse anonymous JSONArray object [duplicate]

This question already has answers here:
Get JSONArray without array name?
(4 answers)
Closed 8 years ago.
Duplicate of Get JSONArray without array name?
Server is returning me the following anonymous JSONArray, I don't know how to parse it. Please help me in parsing it. I am not using any library like Gson, I am using org.json.JSONObject. Pleaes help.
[
{
"provider_metadata": {
"filename": "vr-banner-small.png"
},
"name": "vr-banner-small.png",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "1debc89fa2a4a54599c48ba13f9ccfe1ff7c2360.png",
"width": 183,
"height": 122,
"context": "default",
"updated_at": "2014-04-18T22:54:50+0800",
"created_at": "2014-04-18T22:54:50+0800",
"content_type": "image/png",
"size": 42117,
"id": 190
},
{
"provider_metadata": {
"filename": "Chrysanthemum.jpg"
},
"name": "中文名稱.png",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "2d2ea78282c45fac7c7a3b3e37c77b92b05850cb.jpeg",
"width": 1024,
"height": 768,
"context": "default",
"updated_at": "2014-04-19T03:16:53+0800",
"created_at": "2014-04-18T22:59:11+0800",
"content_type": "image/jpeg",
"size": 879394,
"id": 191
},
{
"provider_metadata": {
"filename": "1111.jpg"
},
"name": "1111.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "605e5a4ec678546d780a72ffa0629c901d65bb1b.jpeg",
"width": 284,
"height": 160,
"context": "default",
"updated_at": "2014-04-18T23:02:24+0800",
"created_at": "2014-04-18T23:02:24+0800",
"content_type": "image/jpeg",
"size": 26337,
"id": 192
},
{
"provider_metadata": {
"filename": "vr-banner-medium.png"
},
"name": "vr-banner-medium.png",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "75ec61e5b12b2d0868886297c073f6228bf9fdcc.png",
"width": 183,
"height": 314,
"context": "default",
"updated_at": "2014-04-18T23:47:34+0800",
"created_at": "2014-04-18T23:47:34+0800",
"content_type": "image/png",
"size": 87214,
"id": 193
},
{
"provider_metadata": {
"filename": "1111.jpg"
},
"name": "1111.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "08ae40d9ef11ce3e6118d172dbffcfba96f282ad.jpeg",
"width": 284,
"height": 160,
"context": "default",
"updated_at": "2014-04-18T23:48:19+0800",
"created_at": "2014-04-18T23:48:19+0800",
"content_type": "image/jpeg",
"size": 26337,
"id": 194
},
{
"provider_metadata": {
"filename": "test.mp3"
},
"name": "test.mp3",
"enabled": false,
"provider_name": "sonata.media.provider.file",
"provider_status": 1,
"provider_reference": "7d0ea143ca408f94633098cd9696fddaba913833.mpga",
"context": "default",
"updated_at": "2014-04-18T23:48:19+0800",
"created_at": "2014-04-18T23:48:19+0800",
"content_type": "audio/mpeg",
"size": 198658,
"id": 195
},
{
"provider_metadata": {
"filename": "Tulips.jpg"
},
"name": "Tulips.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "62c5aed648c9f1189ee248703550ac2dda7c03e0.jpeg",
"width": 1024,
"height": 768,
"context": "default",
"updated_at": "2014-04-19T03:08:07+0800",
"created_at": "2014-04-19T03:08:07+0800",
"content_type": "image/jpeg",
"size": 620888,
"id": 196
},
{
"provider_metadata": {
"filename": "Jellyfish.jpg"
},
"name": "Jellyfish.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "a4212f424dedc8c6c743cc86a1e30e9eb05ab715.jpeg",
"width": 1024,
"height": 768,
"context": "default",
"updated_at": "2014-04-19T03:15:26+0800",
"created_at": "2014-04-19T03:15:26+0800",
"content_type": "image/jpeg",
"size": 775702,
"id": 197
},
{
"provider_metadata": {
"filename": "Hydrangeas.jpg"
},
"name": "Chrysanthemum.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "74648433c8a402533297fa77ee08afc8d6d68a30.jpeg",
"width": 1024,
"height": 768,
"context": "default",
"updated_at": "2014-04-19T03:16:23+0800",
"created_at": "2014-04-19T03:16:03+0800",
"content_type": "image/jpeg",
"size": 595284,
"id": 198
},
{
"provider_metadata": {
"filename": "Jellyfish.jpg"
},
"name": "Chrysanthemum.jpg",
"enabled": false,
"provider_name": "sonata.media.provider.image",
"provider_status": 1,
"provider_reference": "fa93114359b2a49a81c6885f95e3acde74ee882b.jpeg",
"width": 1024,
"height": 768,
"context": "default",
"updated_at": "2014-04-19T03:20:23+0800",
"created_at": "2014-04-19T03:16:53+0800",
"content_type": "image/jpeg",
"size": 775702,
"id": 199
}
]
Assuming you have the response as a java/lang/String:
JSONArray array = new JSONArray(responseString);
public static ArrayList<YourBean> parseJsonObj(Object objPre) {
ArrayList<YourBean> infos = new ArrayList<YourBean>();
try {
if (objPre instanceof JSONArray) {
JSONArray jsList = (JSONArray) objPre;
for (int i = 0; i < jsList.length(); i++) {
JSONObject value = jsList.getJSONObject(i);
infos.add(parseJson(value));
}
} else if (objPre instanceof JSONObject) {
JSONObject obj = (JSONObject) objPre;
infos.add(parseJson(obj));
}
return infos;
} catch (Exception e) {
return infos;
}
}
private static YourBean parseJson(JSONObject value)
throws JSONException {
YourBean info = new YourBean();
if (value.has("name")) {
String name = value.getString("name");
info.setName(name);
}
.......
return info;
}

Categories

Resources