Related
I have to fetch the value from an array nested inside another array. I can fetch values from the first array but not able to fetch values from the second array.
I am able to read the values from the main array but I am unable to read the values from the array which is nested inside it.
JSONObject jsono = new JSONObject(res);
JSONArray jarray = jsono.getJSONArray("data");
for (int i = 0; i < jarray.length(); i++)
{
JSONObject object = jarray.getJSONObject(i);
JSONArray jarray1 = object.getJSONArray("comments_data");
for (int j = 0; j < jarray1.length(); j++)
{
JSONObject object1 = jarray1.getJSONObject(j);
String Namee = object1.getString("username");
String Ratingg = object1.getString("rating");
String Commentt = object1.getString("comment");
Comments comments1 = new Comments();
comments1.setUsername(Namee);
comments1.setRating(Ratingg);
comments1.setComments(Commentt);
comments1.setProfileimage(R.drawable.fav);
commentsList.add(comments1);
}
}
And this is my json.
{
"status": "success",
"msg": " Menu Details",
"data": [
{
"id": "1",
"rest_id": "1",
"menu_rate": "100",
"collection_time": "2:22pm",
"quantity_left": "3",
"food_type": "veg",
"img1": "",
"img2": "",
"img3": "",
"date": "",
"menu_name": "",
"comments_data": [
{
"id": "20",
"user_id": "127",
"res_id": "1",
"comment": "shreyansh s",
"date": "0000-00-00 00:00:00",
"rating": "0.0",
"username": "lucky",
"userimage": "123"
},
{
"id": "19",
"user_id": "126",
"res_id": "1",
"comment": "das",
"date": "0000-00-00 00:00:00",
"rating": "3.0",
"username": "shrey srivastava",
"userimage": "123"
},
{
"id": "18",
"user_id": "126",
"res_id": "1",
"comment": "",
"date": "0000-00-00 00:00:00",
"rating": "3.0",
"username": "shrey srivastava",
"userimage": "123"
},
{
"id": "17",
"user_id": "126",
"res_id": "1",
"comment": "sakjbdkjasbk",
"date": "0000-00-00 00:00:00",
"rating": "3.0",
"username": "shrey srivastava",
"userimage": "123"
},
{
"id": "16",
"user_id": "107",
"res_id": "1",
"comment": "hello",
"date": "0000-00-00 00:00:00",
"rating": "5",
"username": "shreyansh",
"userimage": ""
},
{
"id": "15",
"user_id": "107",
"res_id": "1",
"comment": "hello",
"date": "0000-00-00 00:00:00",
"rating": "5",
"username": "shreyansh",
"userimage": "123"
},
{
"id": "14",
"user_id": "107",
"res_id": "1",
"comment": "hello",
"date": "0000-00-00 00:00:00",
"rating": "5",
"username": "shreyansh",
"userimage": "123"
},
{
"id": "6",
"user_id": "82",
"res_id": "1",
"comment": "good",
"date": "0000-00-00 00:00:00",
"rating": "",
"username": "jaim",
"userimage": "google.com"
}
]
}
]
}
Note carefully how you JSON is built.
First, you have to query for "data". You get JSON-Array. So you traverse it by the indices.
Hence, you query for the specific index in "data" (you can use a loop, of course).
For each iteration, you get a JSONObject, and in it you query for "comments_data".
String json = "{ \"status\": \"success\", \"msg\": \" Menu Details\", \"data\": [ { \"id\": \"1\", \"rest_id\": \"1\", \"menu_rate\": \"100\", \"collection_time\": \"2:22pm\", \"quantity_left\": \"3\", \"food_type\": \"veg\", ...
JSONObject object = new JSONObject(json);
JSONObject jarray1 = jarray_data.getJSONObject(0);
JSONArray comments = jarray1.getJSONArray("comments_data");
I am using Objectbox as an ORM in my application and getting dbexception due to mismatching UID, when I added some extra properties in one of my entity. As I went through the documentation where it is mentioned that if we add or remove properties in your entities objectbox will take care of the changes. But it's not happening in my case. Please have a look at my log stash, entities and default.json once and let me know what could be the possible solution to resolve this issue.
ObjectBox version: v1.2.0
Logs
Caused by: io.objectbox.exception.DbException: Incoming entity ID 8:7509306813647547019 does not match existing UID 8172185837942255744
at io.objectbox.BoxStore.nativeCreate(Native Method)
at io.objectbox.BoxStore.<init>(BoxStore.java:187)
at io.objectbox.BoxStoreBuilder.build(BoxStoreBuilder.java:259)
at com.letsdogether.dogether.dagger.module.ObjectModule.<init>(ObjectModule.java:34)
at com.letsdogether.dogether.newDogetherHome.DogetherApplication.loadObjectsComponent(DogetherApplication.java:104)
at com.letsdogether.dogether.newDogetherHome.DogetherApplication.onCreate(DogetherApplication.java:79)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4969)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1559)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5750)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Entities
Previously my entity looks like this:
#Entity
public class BookingItem {
private long id;
#Id(assignable = true)
private long priority;
private String date;
private String formattedAddress;
private String orderId;
private String type;
private String title;
private int seatCount;
private String pricePerPerson;
private String time;
private String day;
private String redirectUrl;
private String status;
private long experienceId;
private String shareableUrl;
private ToOne<Image> image;
private ToOne<FeedElement> feedElementToOne;
}
and my default.json looks like this:
{
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
"entities": [
{
"id": "1:4340630284304338974",
"lastPropertyId": "8:4962045346664663063",
"name": "BaseExperience",
"properties": [
{
"id": "1:647607068638902600",
"name": "id"
},
{
"id": "2:2702040841419862055",
"name": "actualId"
},
{
"id": "3:3033280429430892352",
"name": "avgRating"
},
{
"id": "4:7218439493883955972",
"name": "customerReviewsCount"
},
{
"id": "5:80984715122814807",
"name": "pricePerPerson"
},
{
"id": "6:3883498391107289246",
"name": "title"
},
{
"id": "7:8998466498535731699",
"indexId": "1:1765637542740785127",
"name": "videoId"
},
{
"id": "8:4962045346664663063",
"indexId": "2:2040540235098101863",
"name": "feedToOneId"
}
],
"relations": []
},
{
"id": "2:7267925106594307597",
"lastPropertyId": "17:4933883640820962465",
"name": "BookingItem",
"properties": [
{
"id": "1:2843152350771579539",
"name": "id"
},
{
"id": "2:3864807135625693365",
"name": "priority"
},
{
"id": "3:2811475968058126998",
"name": "date"
},
{
"id": "4:5994267266359962076",
"name": "formattedAddress"
},
{
"id": "5:8101006061974386478",
"name": "orderId"
},
{
"id": "6:5927620191588993112",
"name": "type"
},
{
"id": "7:6885331133485554648",
"name": "title"
},
{
"id": "8:1499199287986398172",
"name": "seatCount"
},
{
"id": "9:2504021269483806060",
"name": "pricePerPerson"
},
{
"id": "10:7281235595111103399",
"name": "time"
},
{
"id": "11:6617722497399396474",
"name": "day"
},
{
"id": "12:2473985422221126897",
"name": "redirectUrl"
},
{
"id": "13:2904830306792476987",
"name": "status"
},
{
"id": "14:2181195403266779204",
"name": "experienceId"
},
{
"id": "15:3018070061889416768",
"name": "shareableUrl"
},
{
"id": "16:6444561946554419063",
"indexId": "3:1705820361334358507",
"name": "imageId"
},
{
"id": "17:4933883640820962465",
"indexId": "4:3744949801364672550",
"name": "feedElementToOneId"
}
],
"relations": []
},
{
"id": "3:160108942376228999",
"lastPropertyId": "6:8550232341754154098",
"name": "Feed",
"properties": [
{
"id": "1:1692860121377933562",
"name": "id"
},
{
"id": "2:8854384643059958161",
"name": "type"
},
{
"id": "3:7664556112391884481",
"name": "title"
},
{
"id": "4:5817245497381540954",
"name": "seeAll"
},
{
"id": "5:2317329177962315800",
"name": "feedType"
},
{
"id": "6:8550232341754154098",
"indexId": "5:680938987943440350",
"name": "feedElementToOneId"
}
],
"relations": []
},
{
"id": "4:7537217652864317597",
"lastPropertyId": "3:6112954104554042430",
"name": "FeedElement",
"properties": [
{
"id": "1:4926947771749822767",
"name": "id"
},
{
"id": "2:8131453946945993591",
"name": "nextUrl"
},
{
"id": "3:6112954104554042430",
"name": "feedElementType"
}
],
"relations": []
},
{
"id": "5:2348793681892920669",
"lastPropertyId": "8:7488175383318173729",
"name": "Image",
"properties": [
{
"id": "1:638964174063060815",
"name": "actualId"
},
{
"id": "2:4967935003726444020",
"name": "color"
},
{
"id": "3:1353497332618194831",
"name": "id"
},
{
"id": "4:2887915135519113362",
"name": "url"
},
{
"id": "5:8827023004110736151",
"name": "url1080"
},
{
"id": "6:1795038216616196366",
"name": "url160"
},
{
"id": "7:5076768945024929823",
"name": "url360"
},
{
"id": "8:7488175383318173729",
"indexId": "6:4968485658423571275",
"name": "baseExperienceId"
}
],
"relations": []
},
{
"id": "6:2806463549017646468",
"lastPropertyId": "7:1664725566577873631",
"name": "Location",
"properties": [
{
"id": "1:151476474888340297",
"name": "id"
},
{
"id": "2:6138069029925290631",
"name": "city"
},
{
"id": "3:8096792582877437443",
"name": "formattedAddress"
},
{
"id": "4:8477355478574191642",
"name": "mapImgUrl"
},
{
"id": "5:5250680748074469313",
"name": "redirectUrl"
},
{
"id": "6:5264044175718414745",
"name": "lat"
},
{
"id": "7:1664725566577873631",
"name": "lng"
}
],
"relations": []
},
{
"id": "7:1386266048121100599",
"lastPropertyId": "19:3626459003273476368",
"name": "User",
"properties": [
{
"id": "1:7194535953200583315",
"name": "id"
},
{
"id": "2:5880155672016170214",
"name": "age"
},
{
"id": "3:7058496909689094561",
"name": "bio"
},
{
"id": "4:7069552521054985458",
"name": "dob"
},
{
"id": "5:2017478464009051869",
"name": "education"
},
{
"id": "6:7411668424835907052",
"name": "email"
},
{
"id": "7:3598420919065748818",
"name": "fullName"
},
{
"id": "8:55256390599336845",
"name": "gender"
},
{
"id": "10:4287083418016851024",
"name": "numberVerified"
},
{
"id": "11:7486368292287445046",
"name": "phoneNumber"
},
{
"id": "12:332314590071314536",
"name": "shareableUrl"
},
{
"id": "13:3581159011829058253",
"name": "showTutorial"
},
{
"id": "14:45244862441869123",
"name": "username"
},
{
"id": "15:80719230754500568",
"name": "verified"
},
{
"id": "16:8347557177943880481",
"name": "work"
},
{
"id": "17:8060185784410064574",
"indexId": "7:3086777593508744479",
"name": "locationRelationId"
},
{
"id": "18:7093446540087310685",
"indexId": "8:4392926741093129871",
"name": "profilePictureRelationId"
},
{
"id": "19:3626459003273476368",
"name": "host"
}
],
"relations": []
},
{
"id": "8:8172185837942255744",
"lastPropertyId": "4:2905712751785391104",
"name": "Video",
"properties": [
{
"id": "1:4230636119749821279",
"name": "id"
},
{
"id": "2:7059360054054181511",
"name": "nightMode"
},
{
"id": "3:7865268851517989166",
"name": "thumbnailUrl"
},
{
"id": "4:2905712751785391104",
"name": "url"
}
],
"relations": []
}
],
"lastEntityId": "8:8172185837942255744",
"lastIndexId": "8:4392926741093129871",
"lastRelationId": "0:0",
"lastSequenceId": "0:0",
"modelVersion": 4,
"modelVersionParserMinimum": 4,
"retiredEntityUids": [],
"retiredIndexUids": [],
"retiredPropertyUids": [
5678282376830830494
],
"retiredRelationUids": [],
"version": 1
}
Now after adding two new properties to my entity:
#Entity
public class BookingItem {
//region Variables
private long id;
#Id(assignable = true)
private long priority;
private String date;
private String formattedAddress;
private String orderId;
private String type;
private String title;
private int seatCount;
private String pricePerPerson;
private String totalTax; // 1st new propery
private String totalAmount; // 2nd new property
private String time;
private String day;
private String redirectUrl;
private String status;
private long experienceId;
private String shareableUrl;
private ToOne<Image> image;
private ToOne<FeedElement> feedElementToOne;
//endregion
}
and my default.json file:
{
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
"entities": [
{
"id": "1:797065206246794980",
"lastPropertyId": "6:5238604438383493820",
"name": "Feed",
"properties": [
{
"id": "1:4778143127430396941",
"name": "id"
},
{
"id": "2:2758756424257447876",
"name": "type"
},
{
"id": "3:8593664445454711775",
"name": "title"
},
{
"id": "4:3260484052954017714",
"name": "seeAll"
},
{
"id": "5:5439051893044673734",
"name": "feedType"
},
{
"id": "6:5238604438383493820",
"indexId": "1:9094671316112178979",
"name": "feedElementToOneId"
}
],
"relations": []
},
{
"id": "2:6365001579184770311",
"lastPropertyId": "8:4101477603790778141",
"name": "BaseExperience",
"properties": [
{
"id": "1:22769140630409817",
"name": "id"
},
{
"id": "2:9018492547283474382",
"name": "actualId"
},
{
"id": "3:7038610176041110296",
"name": "avgRating"
},
{
"id": "4:6685630808795149304",
"name": "customerReviewsCount"
},
{
"id": "5:700371560430014226",
"name": "pricePerPerson"
},
{
"id": "6:5016151397612468696",
"name": "title"
},
{
"id": "7:1936717642548225179",
"indexId": "2:1430584179264421000",
"name": "videoId"
},
{
"id": "8:4101477603790778141",
"indexId": "3:2605016395080192788",
"name": "feedToOneId"
}
],
"relations": []
},
{
"id": "3:6907123400855664498",
"lastPropertyId": "7:2458659011456972963",
"name": "Location",
"properties": [
{
"id": "1:7686305118064424277",
"name": "id"
},
{
"id": "2:2382662573706119095",
"name": "city"
},
{
"id": "3:6622007474920998885",
"name": "formattedAddress"
},
{
"id": "4:4372387463973357662",
"name": "mapImgUrl"
},
{
"id": "5:4242635850865049170",
"name": "redirectUrl"
},
{
"id": "6:6362649356171979743",
"name": "lat"
},
{
"id": "7:2458659011456972963",
"name": "lng"
}
],
"relations": []
},
{
"id": "4:1653889744595737127",
"lastPropertyId": "4:1222058476100793989",
"name": "Video",
"properties": [
{
"id": "1:8884142329290866772",
"name": "id"
},
{
"id": "2:9063641434858436120",
"name": "nightMode"
},
{
"id": "3:6750530027777030938",
"name": "thumbnailUrl"
},
{
"id": "4:1222058476100793989",
"name": "url"
}
],
"relations": []
},
{
"id": "5:2328616238996484251",
"lastPropertyId": "18:8914368039716260545",
"name": "User",
"properties": [
{
"id": "1:8699946482619760537",
"name": "id"
},
{
"id": "2:4839102804066560980",
"name": "age"
},
{
"id": "3:4125992685805831147",
"name": "bio"
},
{
"id": "4:1279509102068824378",
"name": "dob"
},
{
"id": "5:2555427309043212840",
"name": "education"
},
{
"id": "6:5872521230199756193",
"name": "email"
},
{
"id": "7:3289121993356321",
"name": "fullName"
},
{
"id": "8:568408267657413444",
"name": "gender"
},
{
"id": "9:5476542265369423309",
"name": "host"
},
{
"id": "10:7787973054527294793",
"name": "numberVerified"
},
{
"id": "11:7196291790521558535",
"name": "phoneNumber"
},
{
"id": "12:1859664059288662356",
"name": "shareableUrl"
},
{
"id": "13:4056506903853763516",
"name": "showTutorial"
},
{
"id": "14:5747800400884843324",
"name": "username"
},
{
"id": "15:3715522420100243828",
"name": "verified"
},
{
"id": "16:3996139181248738872",
"name": "work"
},
{
"id": "17:3912614163504861034",
"indexId": "4:724013235730952653",
"name": "locationRelationId"
},
{
"id": "18:8914368039716260545",
"indexId": "5:9128231055610190580",
"name": "profilePictureRelationId"
}
],
"relations": []
},
{
"id": "6:162879391314678826",
"lastPropertyId": "19:5998558359424914894",
"name": "BookingItem",
"properties": [
{
"id": "1:7685664473128076565",
"name": "id"
},
{
"id": "2:4691963051617887607",
"name": "priority"
},
{
"id": "3:4751608989851978419",
"name": "date"
},
{
"id": "4:4298668252649681543",
"name": "formattedAddress"
},
{
"id": "5:3557896982175720249",
"name": "orderId"
},
{
"id": "6:5444396912371992185",
"name": "type"
},
{
"id": "7:6350566628717896888",
"name": "title"
},
{
"id": "8:5815948248926709539",
"name": "seatCount"
},
{
"id": "9:1347517584208111506",
"name": "pricePerPerson"
},
{
"id": "10:161182016726729049",
"name": "totalTax"
},
{
"id": "11:2603677420345643342",
"name": "totalAmount"
},
{
"id": "12:6964519603978301018",
"name": "time"
},
{
"id": "13:6563743671015329186",
"name": "day"
},
{
"id": "14:5252213579952934956",
"name": "redirectUrl"
},
{
"id": "15:213202584538548112",
"name": "status"
},
{
"id": "16:2664627056996276806",
"name": "experienceId"
},
{
"id": "17:5051545379861430992",
"name": "shareableUrl"
},
{
"id": "18:4513563003576451503",
"indexId": "6:4794120774209056940",
"name": "imageId"
},
{
"id": "19:5998558359424914894",
"indexId": "7:2963448740658161805",
"name": "feedElementToOneId"
}
],
"relations": []
},
{
"id": "7:6072605387056962258",
"lastPropertyId": "8:620926858576597520",
"name": "Image",
"properties": [
{
"id": "1:4722495423798219248",
"name": "actualId"
},
{
"id": "2:5785809790036589091",
"name": "color"
},
{
"id": "3:898405045397421733",
"name": "id"
},
{
"id": "4:5442888368829266995",
"name": "url"
},
{
"id": "5:3501485434468197765",
"name": "url1080"
},
{
"id": "6:1316954607651171513",
"name": "url160"
},
{
"id": "7:2942445530687114413",
"name": "url360"
},
{
"id": "8:620926858576597520",
"indexId": "8:7864085141767381960",
"name": "baseExperienceId"
}
],
"relations": []
},
{
"id": "8:7509306813647547019",
"lastPropertyId": "3:6958687385472305063",
"name": "FeedElement",
"properties": [
{
"id": "1:3560464698535580090",
"name": "id"
},
{
"id": "2:7436822921002379968",
"name": "nextUrl"
},
{
"id": "3:6958687385472305063",
"name": "feedElementType"
}
],
"relations": []
}
],
"lastEntityId": "8:7509306813647547019",
"lastIndexId": "8:7864085141767381960",
"lastRelationId": "0:0",
"lastSequenceId": "0:0",
"modelVersion": 4,
"modelVersionParserMinimum": 4,
"retiredEntityUids": [],
"retiredIndexUids": [],
"retiredPropertyUids": [],
"retiredRelationUids": [],
"version": 1
}
In case you deleted the app/objectbox-models/default.json and uninstalled the app from your android device but the issue still prevails check your manifest file for android:allowBackup="true" and change it to false. Then repeat the steps again.
This cost me an hour of my life, hope it helps.
Source: The Nuke Option
Here's the solution as stated in the GitHub issue:
The IDs of the two versions in your project are totally off: https://www.diffchecker.com/PF3UlSM7
Please revert to the old "default.json" file and rebuild. There should only be little differences in this file on updates.
Yep. You probably changed your object structure after it created once.
The easiest option to solve it:
Like you said, If it possible you need to remove the default.json file (that build automatically while you build your project). and in the next build it will create again.
I recommend you to read about Resolving Meta Model Conflicts in objectbox documentation.
My issue is resolved and the issue actually is that I deleted my old default.json file by mistake which i didn't have to, which eventually led to regenerate the ids of all the entities and caused me a mismatching UID exception. Thanks to Markus Junginger.
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 following pattern of JSON
{
"menu": [{
"id": "74",
"parent_id": "0",
"title": "Mobiles & Tablets",
"menu_type": "7",
"menu_icon_image": "",
"link": "#",
"childs": [{
"id": "75",
"parent_id": "74",
"title": "Mobile Phones",
"menu_type": "7",
"menu_icon_image": "",
"link": "categories/mobile-tablets"
}, {
"id": "76",
"parent_id": "74",
"title": "Mobile Accessories",
"menu_type": "7",
"menu_icon_image": "",
"link": "#"
}, {
"id": "77",
"parent_id": "74",
"title": "Tablets",
"menu_type": "7",
"menu_icon_image": "",
"link": "#"
}, {
"id": "78",
"parent_id": "74",
"title": "Audio & Video",
"menu_type": "7",
"menu_icon_image": "",
"link": "#"
}, {
"id": "79",
"parent_id": "74",
"title": "Laptops",
"menu_type": "7",
"menu_icon_image": "",
"link": "#"
}]
}, {
"id": "80",
"parent_id": "0",
"title": "WOMEN",
"menu_type": "7",
"menu_icon_image": "",
"link": "#",
"childs": [{
"id": "81",
"parent_id": "80",
"title": "GIRLS CLOTHING",
"menu_type": "7",
"menu_icon_image": "",
"link": "categories/womens-clothing"
}]
}],
"slider": [{
"id": "56",
"url": "#",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-itwQr56f76f6df2bea.png/88e5b614324080684af061c510496d29",
"title": "Mobile Test Slider",
"image": null,
"days": null
}, {
"id": "55",
"url": "#",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-uIXFZ56f76efbcd627.png/e5a0e22dcb0de1007c88c16db1aebb7f",
"title": "Mobile Test Slider",
"image": null,
"days": null
}, {
"id": "52",
"url": "#",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-QULkY56f7719eb0915.png/a4d0065b56b57b7d01d44873bbdb1df8",
"title": "Mobile Test Slider",
"image": null,
"days": null
}, {
"id": "51",
"url": "#",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-L0ROK56f7716acccf0.png/e194ea4403c4b4b7e17f1fecfa329f22",
"title": "Mobiles & Tablets",
"image": null,
"days": null
}, {
"id": "1",
"url": "",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-qtvVk56f60fd0379b9.jpg/510c150029fd29d1d77b869d837b126e",
"title": "Slider Add",
"image": null,
"days": null
}],
"advertise": [{
"id": "54",
"usrl": "categories/mobile-tablets",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/1-fl-IWkmH56f66a2b60bde.jpg/05571c3c78954e1a461b87bd62698273",
"title": "Mobile phone home page advertise",
"image": null,
"days": null
}, {
"id": "53",
"usrl": "categories/mobile-tablets",
"default_image": "https://s3.amazonaws.com/atbdev/cache/advertis_img/3-fl-YK1pI56f5102a7237b.png/118b3074314006a62a7f10867a447be6",
"title": "Mobile phone home page advertise",
"image": null,
"days": null
}]
}
List<ExpanTitelandTotal> result1111 = new ArrayList<ExpanTitelandTotal>();
for (int i = 0; i < menuArrayList.size(); i++) {
ExpanTitelandTotal mExpanTitelandTotal11 = new ExpanTitelandTotal();
mExpanTitelandTotal11.setTitle(menuArrayList.get(i).getTitle());
mExpanTitelandTotal11.setLink(menuArrayList.get(i).getLink());
mExpanTitelandTotal11.setId(Integer.parseInt(menuArrayList.get(i).getId()));
//result1111.add(mExpanTitelandTotal11);
if (mGetDrawerAndHome.getMenu().get(i).getChilds().size() > 0) {
mExpanTitelandTotal11.setIsMultiple(true);
Log.d("mGetDrawerAndHome.getMenu().get(i).getChilds().size() ",String .valueOf(mGetDrawerAndHome.getMenu().get(i).getChilds().size()));
for (int j = 0; j < mGetDrawerAndHome.getMenu().get(i).getChilds().size(); j++)
{
Log.d("Sub Menu", mGetDrawerAndHome.getMenu().get(i).getChilds().get(j).getTitle());
ExpanTitelandTotal mExpanTitelandTotal = new ExpanTitelandTotal();
mExpanTitelandTotal.setTitle(mGetDrawerAndHome.getMenu().get(i).getChilds().get(j).getTitle());
mExpanTitelandTotal.setLink(mGetDrawerAndHome.getMenu().get(i).getChilds().get(j).getLink());
mExpanTitelandTotal.setId(Integer.parseInt(mGetDrawerAndHome.getMenu().get(i).getChilds().get(j).getId()));
result1111.add(mExpanTitelandTotal);
}
} else {
mExpanTitelandTotal11.setIsMultiple(false);
}
mExpanTitelandTotal11.setItemList(result1111);
mArrayListExpanTitelandTotals.add(mExpanTitelandTotal11);
}
listAdapterTNA = new ExpandableListAdapterTNA(ActivityDrawer.this, mArrayListExpanTitelandTotals, mExpandableListView);
mExpandableListView.setAdapter(listAdapterTNA);
mExpandableListView.setIndicatorBounds(10, 80);
mExpandableListView.setDivider(null);
above is my code and when i run this i get following output
In expandable list view two different category data store in all main category data ? any idea how can i solve this ?
Create a new List object inside the first for loop sentence:
List<ExpanTitelandTotal> result1111;
for (int i = 0; i < menuArrayList.size(); i++) {
result1111 = new ArrayList<ExpanTitelandTotal>();
/////YOUR CODE
}
For example : if the given below is json of the person's profile on facebook got thorugh facebook sdk login through android app , How we will get the School Name fron the education Field in th json data in android . Please Help
Data :
{
"id": "1464730016",
"name": "Ravi Tamada",
"first_name": "Ravi",
"last_name": "Tamada",
"link": "https://www.facebook.com/ravi8x",
"username": "ravi8x",
"birthday": "12/22/1988",
"hometown": {
"id": "112158005464147",
"name": "Baruva"
},
"location": {
"id": "102186159822587",
"name": "Chennai, Tamil Nadu"
},
"bio": "Author: www.androidhive.info\r\nCo-author: www.9lessons.info",
"work": [
{
"employer": {
"id": "179366562092719",
"name": "ByteAlly"
},
"location": {
"id": "102186159822587",
"name": "Chennai, Tamil Nadu"
},
"position": {
"id": "124917314217511",
"name": "Product Head"
}
]
}
],
"favorite_athletes": [
{
"id": "18620649907",
"name": "Virat Kohli"
}
],
"education": [
{
"school": {
"id": "131587206873093",
"name": "Raghu Engineering College (REC)"
},
"degree": {
"id": "140065339390579",
"name": "B.Tech"
},
"year": {
"id": "142963519060927",
"name": "2010"
},
"type": "Graduate School",
"classes": [
{
"id": "192259410803415",
"name": "2010",
"with": [
{
"id": "584960408",
"name": "Santosh Patnaik"
}
],
"from": {
"id": "584960408",
"name": "Santosh Patnaik"
}
}
]
}
],
"gender": "male",
"relationship_status": "Single",
"website": "www.androidhive.info\nwww.9lessons.info\nwww.twitter.com/ravitamada\nwww.about.me/rv",
"timezone": 5.5,
"locale": "en_US",
"languages": [
{
"id": "106059522759137",
"name": "English"
},
{
"id": "107617475934611",
"name": "Telugu"
},
{
"id": "112969428713061",
"name": "Hindi"
},
{
"id": "343306413260",
"name": "Tamil"
}
],
"verified": true,
"updated_time": "2012-03-02T17:04:18+0000"
}
JSONObject jsonResult = new JSONObject(jsonUser);
JSONArray data = jsonResult.getJSONArray("education");
if(data != null)
{
for(int i = 0 ; i < data.length() ; i++)
{
JSONObject c = data.getJSONObject(i);
String type = c.getString("type");
if(type.equalsIgnoreCase("college"))
{
JSONObject school = c.getJSONObject("school");
String id2 = school.getString("id");
String name2 = school.getString("name");
JSONObject year = c.getJSONObject("year");
String id_y = school.getString("id");
String name_y = school.getString("name");
}
}
}
Supposing that you've this json into a jsonObject that you retrieve as response, this is the way:
// Get jsonArray 'education' from main jsonObject
JSONArray jsonArrayEducation = jsonObject.getJSONArray("education");
JSONObject jsonSchool = jsonArrayEducation.getJSONObject("school");
Note that if you are interested only at the name, you can group the two lines above into
JSONObject jsonSchool = jsonObject.getJSONArray("education").getJSONObject("school");
// get school name
String schoolName = jsonSchool.getString("name");