Related
Here's the JSON where jsonObject key is dynamic :
{
"CH000032": [
{
"type": "event",
"details": {
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
}
}
],
"CH000033": [
{
"type": "event",
"details": {
"programID": "EP10000132",
"programType": "EPISODE",
"title": "A Chic Bar in Ibiza",
"seriesTitle": "Two and a Half Men",
"seasonNumber": 12,
"epsiodeNumber": 2,
"year": "2014",
"rating": "TV-14",
"durationSec": 1260,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Comedy",
"Romance"
],
"description": "Alan has second thoughts about getting married when Walden has him sign a prenup.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_crop,h_405,w_270//l_Copyright_e3jt1k/v1508831090/2AndHalfmen_splkro.jpg"
}
}
]
}
I would like to parse this JSON. Please let me know how should the class
be written with #SerializedName annotation using Retrofit.
Note : CH000032, CH000033 etc are dynamic.
You can use Map<String, ModelClassName> in your model class for dynamic like below :-
public class Data {
#SerializedName("your_key")
#Expose
private Map<String, ModelClassName> result;
//....
}
this can help to parse dynamic key in retrofit.
What you are asking will take much work , instead a better approach will be to change the structure o json to something like this -
"data": [
{
"type": "event",
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
},
{
"type": "event",
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
}]
I'm using the LinkedIn Android SDK downloaded from here (version 1.1.4) and have set up authentication already like this:
liSessionManager.init(activity,
Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS), authListener);
and everything works fine, but when I want to get the profile data, returned json is missing fields like summary in job positions and general summary for the given profile.
The request is made like this:
apiHelper.getRequest(activity, GET_LINKED_IN_PROFILE_URL, apiListener);
where GET_LINKED_IN_PROFILE_URL is https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,phone-numbers,public-profile-url,picture-url,picture-urls::(original))?format=json.
The response is as follows:
{
"currentShare": {
"author": {
"firstName": "Name",
"id": "***",
"lastName": "Surname"
},
"comment": "I've made my LinkedIn profile visual! Check it out and get yours!",
"content": {
"description": "some descr",
"eyebrowUrl": "http://url.com/me/7827748?m_in&user_id=***",
"resolvedUrl": "http://url.com/me/7827748?m_in&user_id=***",
"shortenedUrl": "http://linkedin.in/url",
"submittedImageUrl": "https://www.url.com/logo-share.png",
"submittedUrl": "https://www.url.com/me/***?m_in&user_id=***",
"thumbnailUrl": "https://media.licdn.com/media-proxy/ext?w=80&h=100&f=&hash=usON2E%2F4FqEGtIT5dsadsaaD&ora=1%2CaFBCTXdkRmpGL2lvQUFBPQ%2CxAVta5g-0R65wFUbzx0776dsaulz-50hKCpDZEXX8HmW3uZHfgasdapuGJ-n08ARIZ3Bex1svPLf5AmX_Us3r",
"title": "title"
},
"id": "s1291360434",
"source": {
"application": {"name": "app"},
"serviceProvider": {"name": "LINKEDIN"}
},
"timestamp": 1346884888000,
"visibility": {"code": "anyone"}
},
"emailAddress": "***#gmail.com",
"firstName": "Name",
"formattedName": "Name Surname",
"headline": "Job position",
"id": "***",
"industry": "Computer Software",
"lastName": "Surname",
"location": {
"country": {"code": "pl"},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"numConnections": 229,
"numConnectionsCapped": false,
"pictureUrl": "https://media.licdn.com/mpr/mprx/photourl",
"pictureUrls": {
"_total": 1,
"values": ["https://media.licdn.com/mpr/mprx/photourl"]
},
"positions": {
"_total": 1,
"values": [{
"company": {
"id": 2795963,
"industry": "Information Technology & Services",
"name": "Company 1",
"size": "11-50",
"type": "Privately Held"
},
"id": ***,
"isCurrent": true,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 1,
"year": 2016
},
"title": "Job position"
}]
},
"publicProfileUrl": "https://www.linkedin.com/in/username/41219"
}
When I use the same url in the API Console at https://apigee.com/console/linkedin, the response looks like this:
{
"currentShare": {
"author": {
"firstName": "Name",
"id": "***",
"lastName": "Surname"
},
"comment": "I've made my LinkedIn profile visual! Check it out and get yours!",
"content": {
"description": "some descr",
"eyebrowUrl": "http://url.com/me/7827748?m_in&user_id=***",
"resolvedUrl": "http://url.com/me/7827748?m_in&user_id=***",
"shortenedUrl": "http://linkedin.com/shortened",
"submittedImageUrl": "https://www.url.com/logo-share.png",
"submittedUrl": "https://www.url.com/me/***?m_in&user_id=***",
"thumbnailUrl": "https://media.licdn.com/media-proxy/ext?w=80&h=100&f=&hash=usON2E%2F4FqEGtIT5dsadsaaD&ora=1%2CaFBCTXdkRmpGL2lvQUFBPQ%2CxAVta5g-0R65wFUbzx0776dsaulz-50hKCpDZEXX8HmW3uZHfgasdapuGJ-n08ARIZ3Bex1svPLf5AmX_Us3r",
"title": "title"
},
"id": "s1291360434",
"source": {
"application": {
"name": "app"
},
"serviceProvider": {
"name": "LINKEDIN"
}
},
"timestamp": 1346884888000,
"visibility": {
"code": "anyone"
}
},
"emailAddress": "***#gmail.com",
"firstName": "Name",
"formattedName": "Name Surname",
"headline": "Job position",
"id": "***",
"industry": "Computer Software",
"lastName": "Surname",
"location": {
"country": {
"code": "pl"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"numConnections": 229,
"numConnectionsCapped": false,
"pictureUrl": "https://media.licdn.com/mpr/mprx/photourl",
"pictureUrls": {
"_total": 1,
"values": [
"https://media.licdn.com/mpr/mprx/photourl"
]
},
"positions": {
"_total": 1,
"values": [
{
"company": {
"id": 2795963,
"industry": "Information Technology & Services",
"name": "Company 1",
"size": "11-50",
"type": "Privately Held"
},
"id": 22222,
"isCurrent": true,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 1,
"year": 2016
},
"title": "Job position"
},
{
"company": {
"id": 611639,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 2,
"year": 2016
},
"id": 1111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 4,
"year": 2015
},
"summary": "Summary of job",
"title": "Senior Android Developer"
},
{
"company": {
"id": 1111,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 3,
"year": 2015
},
"id": 111111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 4,
"year": 2014
},
"summary": "short summary",
"title": "Android/iOS Developer"
},
{
"company": {
"id": 11111,
"industry": "Internet",
"name": "Company 2",
"size": "51-200",
"type": "Privately Held"
},
"endDate": {
"month": 3,
"year": 2014
},
"id": 1111111,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Wroclaw, Lower Silesian District, Poland"
},
"startDate": {
"month": 2,
"year": 2013
},
"summary": "android applications developer.\ncross-platform mobile application testing (iOS, Windows 8)",
"title": "Junior Android Developer"
},
{
"company": {
"id": 3333,
"industry": "Information Technology & Services",
"name": "Company 3",
"size": "201-500",
"type": "Privately Held"
},
"endDate": {
"month": 11,
"year": 2011
},
"id": 3333333,
"isCurrent": false,
"location": {
"country": {
"code": "pl",
"name": "Poland"
},
"name": "Warsaw, Masovian District, Poland"
},
"startDate": {
"month": 7,
"year": 2011
},
"summary": "Intern ",
"title": "Internship"
}
]
},
"publicProfileUrl": "https://www.linkedin.com/in/username/41219"
}
Which shows that the Android SDK's response is missing some job positions and a summary for a profile.
It turned out LinkedIn is not returning fields that have no value. If you don't setup a summary in your profile, then there won't be a field named summary in the response. (Don't expect anything like "summary" : null)
Additionally only first position is returned for a given profile while using r_basicprofile scope. It's confusing since this one profile is returned in the positions array.
based on https://developer.linkedin.com/docs/fields/basic-profile :
Positions - An object representing the member's current position.
See Position Fields for a description of the fields available within this object.
The reason why the API Console's response was having all job positions is because it asked for r_fullprofile scope while authenticating
I have download this CONTENTFUL CMS product catalogue demo ->https://github.com/contentful/product-catalogue-android. Im using android studio 1.4.
I have set the public token ID in the const.java accordingly but it still get error. At first i think maybe i have set a wrong setting at content_type field setting. But i still cannot find my solution. My error look like below and ive attached images for you to see,
10-23 18:56:18.820 2094-2147/catalogue.contentful E/SQLiteLog: (1) no such table: entry_nulundg0rwhzuvm0suntyxvdzufjrq
(1) no such table: entry_ne90ogm2rdjxuxfnb2fvs2dzbtgysw
This is my JSON statement from my CONTENTFUL "Product": content_type
{
"name": "Product",
"description": "",
"displayField": "productName",
"fields": [
{
"name": "productName",
"id": "productName",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "productDescription",
"id": "productDescription",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "sizetypecolor",
"id": "sizetypecolor",
"type": "Symbol"
},
{
"name": "images",
"id": "images",
"type": "Array",
"items": {
"type": "Link",
"linkType": "Asset",
"validations": []
},
"validations": []
},
{
"name": "categories",
"id": "categories",
"type": "Link",
"linkType": "Entry",
"validations": [
{
"linkContentType": [
"5In484EhYQS4ICSauCeAcE"
]
}
]
},
{
"name": "tags",
"id": "tags",
"type": "Array",
"items": {
"type": "Symbol",
"validations": []
},
"validations": []
},
{
"name": "price",
"id": "price",
"type": "Number",
"validations": []
},
{
"name": "brand",
"id": "brand",
"type": "Link",
"linkType": "Entry",
"validations": [
{
"linkContentType": [
"5gTQW9EcAwEYEc42WGgaEu"
]
}
]
},
{
"name": "quantity",
"id": "quantity",
"type": "Integer",
"localized": false,
"validations": []
},
{
"name": "sku",
"id": "sku",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "website",
"id": "website",
"type": "Symbol",
"localized": false,
"validations": []
}
],
"sys": {
"id": "4Ot8c6D2qQqgoaUKgYm82K",
"type": "ContentType",
"createdAt": "2015-10-23T13:04:54.705Z",
"createdBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
},
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "b7di2z8ukacn"
}
},
"firstPublishedAt": "2015-10-23T13:04:59.904Z",
"publishedCounter": 17,
"publishedAt": "2015-10-23T17:33:41.088Z",
"publishedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
},
"publishedVersion": 41,
"version": 42,
"updatedAt": "2015-10-23T17:33:41.107Z",
"updatedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
}
}
}
And this is my Android Studio coding
public Product$$ModelHelper() {
fields.add(FieldMeta.builder().setId("productName").setName("name").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("productDescription").setName("description").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("sizetypecolor").setName("sizeTypeColor").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("image").setName("images").setArrayType("com.contentful.vault.Asset").build());
fields.add(FieldMeta.builder().setId("tags").setName("tags").setSqliteType("BLOB").setArrayType("java.lang.String").build());
fields.add(FieldMeta.builder().setId("categories").setName("categories").setArrayType("catalogue.contentful.vault.Category").build());
fields.add(FieldMeta.builder().setId("price").setName("price").setSqliteType("DOUBLE").build());
fields.add(FieldMeta.builder().setId("brand").setName("brand").setLinkType("ENTRY").build());
fields.add(FieldMeta.builder().setId("quantity").setName("quantity").setSqliteType("INT").build());
fields.add(FieldMeta.builder().setId("sku").setName("sku").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("website").setName("website").setSqliteType("STRING").build());
}
#Override
public List<FieldMeta> getFields() {
return fields;
}
#Override
public String getTableName() {
return "entry_ne90ogm2rdjxuxfnb2fvs2dzbtgysw";
}
My Android Studio project error screenshot
I really appreciate if anyone can help me with this problem.Because this app is a demo, i really think my problem is at my setting at CONTENTFUL, but maybe i need second opinion. Please help.
Thank you.
Hello Mario from Contentful here,
As I could see from the code you provided, it seems as if you changed the generated classes. Can you try changing the Product.java using the annotations provided by vault to create a Product matching your data?
This also needs to be done with all the other ContentTypes, you created in the Contentful-WebUI.
I am parsing json object from facebook.
In my facebook json object, there are string keys inside key array "data".
My Code as follows,
"data": [
{
"id": "100001211447563_300696056647440",
"from": {
"name": "Seho Lee",
"id": "100001211447563"
},
"story": "Seho Lee is now using Facebook in English (US).",
"story_tags": {
"0": [
{
"id": 100001211447563,
"name": "Seho Lee",
"offset": 0,
"length": 8
}
]
},
"type": "status",
"created_time": "2012-01-19T09:13:04+0000",
"updated_time": "2012-01-19T09:13:04+0000",
"comments": {
"count": 0
}
},
{
"id": "100001211447563_298802933503419",
"from": {
"name": "Seho Lee",
"id": "100001211447563"
},
"story": "Seho Lee started using Graph API Explorer.",
"story_tags": {
"23": [
{
"id": 145634995501895,
"name": "Graph API Explorer",
"offset": 23,
"length": 18
}
],
"0": [
{
"id": 100001211447563,
"name": "Seho Lee",
"offset": 0,
"length": 8
}
]
},
"picture": "http://photos-a.ak.fbcdn.net/photos-ak-snc1/v43/11/145634995501895/app_1_145634995501895_4870.gif",
"link": "http://developers.facebook.com/tools/explorer/",
"caption": "A tool to help you browse objects within the Facebook Graph API, manage permissions, obtain access tokens and generally learn how it all works.",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100001211447563/posts/298802933503419"
},
{
"name": "Like",
"link": "http://www.facebook.com/100001211447563/posts/298802933503419"
}
],
"type": "link",
"created_time": "2012-01-16T09:47:57+0000",
"updated_time": "2012-01-16T09:47:57+0000",
"comments": {
"count": 0
}
},
{
"id": "100001211447563_298789650171414",
"from": {
"name": "Seho Lee",
"id": "100001211447563"
},
"story": "Seho Lee likes myFBCovers.com.",
"story_tags": {
"15": [
{
"id": 160901873998019,
"name": "myFBCovers.com",
"offset": 15,
"length": 14
}
],
"0": [
{
"id": 100001211447563,
"name": "Seho Lee",
"offset": 0,
"length": 8
}
]
},
"type": "status",
"created_time": "2012-01-16T08:57:33+0000",
"updated_time": "2012-01-16T08:57:33+0000",
"comments": {
"count": 0
}
}
when I parsing this json object, String key "likes" is sometimes exist and sometimes do not exist in "data" jsonArray. So when I parsing JsonString "likes", sometimes I gets JSONException since I am parsing null value. Is there any way to skipping "null" json value?
Please help me regarding this.
if try catch it, next processes will be skipped.
you can check by isNull("name") method.
Edit: this is to check key. since you mentioned key exists sometimes. did you mean the value?
use JSONObjects method has(key)
data = (JSONObject) new JSONTokener(jsonObjRecv.toString()).nextValue();
if data.has("like"){
...
}
to check whether the value is null check with isNull("name")
I have a problem getting my feeds.
1- I (emiliano nunez) post a photo with my cellphone (android) and add (With) "hall 9000".
I (hall 9000) get feeds by graph api:
https://graph.facebook.com/me/feed?access_token=..........
{
"from": {
"name": "Emiliano Gustavo Nu\u00f1ez",
"id": "100001535156886"
},
"type": "photo",
"picture": "http://photos-a.ak.fbcdn.net/hphotos-ak-snc7/386161_265139050213931_100001535156886_723669_443588989_s.jpg",
"message": "Ibrick test",
"with_tags": {
"data": [
{
"name": "Hal Nuevemil",
"id": "100003200111123"
}
]
},
"to": {
"data": [
{
"name": "Hal Nuevemil",
"id": "100003200111123"
}
]
},
"id": "100001535156886_265139076880595",
"created_time": "2011-12-29T18:43:49+0000"
}
I can see "with_tags" section with hall 9000 :)
Until now perfect..
2 - then i repeat the procedure with other photo ... and get:
{
"from": {
"name": "Emiliano Gustavo Nu\u00f1ez",
"id": "100001535156886"
},
"type": "photo",
"picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-snc7/396071_265171810210655_100001535156886_723868_1962904772_s.jpg",
"id": "100001535156886_265171840210652",
"created_time": "2011-12-29T19:44:56+0000"
},
I don't see "with_tags" section.
:(
For more details:
http://i.stack.imgur.com/N4knz.png
http://i.stack.imgur.com/uPqvh.png