How to get Array of array(result values Specially CommentUser[] and BarLike[]) from json string using jackson in Android? - android

I want to get the value of CommentUser[] and BarLike[] but not able to fetch that array of array from this JSON string .
Please refer this link for View my parsing code :
https://www.dropbox.com/s/rws784060dblbq4/Untitled.png?dl=0
{
"success": "1",
"msg": "Closures found.",
"details": {
},
"result": [{
"name": "Miles Davis",
"birthDate": -1376027600000,
"CommentUser": [{
"like": 0,
"unlike": 1
}],
"BarLike": [{
"like": 0,
"unlike": 1
}]
}]
}

Related

Moshi parse two-dimensional array

How to use Moshi+Retrofit to parse the data format of the two-dimensional array type returned by the server
{
"code": 200,
"msg": null,
"data": {
"page": 1,
"size": 10,
"total": 2,
"inner_data": [
[{
"transaction_id": "1626105263092142080",
"creat_time": "1676528680953"
}]
]
}
}

Dynamic JSON parsing

I am a newbie to android. I am stuck at JSON parsing.
Following is my JSON, in this, the type of menu categories will be dynamic, and I want to arrange this JSON in sectioned recycler view.
Please help me out.
This is my JSON
{
"menu_items": {
"Plat": [{
"menu_name": "jambon à l'os",
"menu_cost": "18.00",
"menu_count": "1",
"category": "Plat",
"menu_tax": "5.50",
"code": "€"
},
{
"menu_name": "tacos",
"menu_cost": "6.00",
"menu_count": "1",
"category": "Plat",
"menu_tax": "5.50",
"code": "€"
}
],
"Entrée": [{
"menu_name": "avocat",
"menu_cost": "7.50",
"menu_count": "1",
"category": "Entrée",
"menu_tax": "5.50",
"code": "€"
}]
},
"order_data": {
"order_id": "278",
"order_number": "REF-5d5e6b86",
"created_at": "1566468998",
"instructions": "",
"fullname": "Rohan Chitnis",
"phonenumber": "7610771871",
"useraddress": "Brest, France",
"image_path": "https://restau-at-home.bzh/uploads/attachments/Jellyfish_2019_08_21_10_49_21.jpg",
"wp": "pune",
"code": "€",
"promocode": null,
"promo_value": null,
"promo_type": null
},
"order_details": {
"total_items": "3",
"order_total": "31.50"
},
"promo_applied": "0",
"error": {
"code": "13",
"status": "200",
"message": "Ok"
}
}
Check this out. Create a generic response class. Extend your classes from that class. To do this properly you can look at Java Generics and Inheritance topics if you are using Java. And then search about Sectioned RecyclerView in Android. Here is a library for this.

JSON data - How to parse?

Suppose I have data in JSON. How can I parse the data so I can get the values of nested objects (e.g. kind, id and title)?
My JSON data is:
{
"kind": "youtube#playlistItemListResponse",
"items": [
{
"id": "UExkc1JWcGJNV19LSH",
"items":[
{
"title": "New Updates",
}
],
}],
}
Well you should remove all the commas since last items should not be followed by one.
So more like:
{
"kind": "youtube#playlistItemListResponse",
"items": [{
"id": "UExkc1JWcGJNV19LSH",
"items": [{
"title": "New Updates"
}]
}]
}
Other than that you can just use JSONObject lib and extract the value you need. For example to get the kind:
JSONObject jsonObj = new JSONObject(strInput);
String kind = jsonObj.getString("kind"); // kind now contains "youtube#playlistItemListResponse"
where strInput is the above json as a string.
More info: https://developer.android.com/reference/org/json/JSONObject

Obtaining facebook cover photos

How I can get the cover photo of the albums of a user in my application?
Currently, I have a json like this:
"id": "00000",
"albums": {
"data": [
{
"id": "428076573767",
"from": {
"name": "Benjamin",
"id": "00000"
},
"name": "Profile Pictures",
"link": "https://www.facebook.com/album.php?fbid=00000&id=00000&aid=00000",
"cover_photo": "10151465301937683",
"privacy": "everyone",
"count": 57,
"type": "profile",
"created_time": "2010-09-05T08:42:19+0000",
"updated_time": "2013-04-27T23:53:11+0000",
"can_upload": false
},
}
How I can get the cover_photo by URL?
You can get cover photo by adding this into URL. No need to extract cover_photo from Json .
album['id']?>/picture?access_token=12345
// where album is JSON array and access_token is random here..
Try this. It will work.

How can i parse a enum value through GSon parser in android application

I am getting the response
{
"returnCode": "0",
"message": "Sucessfully get credit card for value(1) ",
"token": "",
"CreditCard": {
"class": "CreditCard",
"id": 1,
"bankName": "NA",
"cardNumber": "1233435467789",
"ccvNumber": "3455",
"dateCreated": "2012-02-10T10:20:06Z",
"expiryDate": "2012-02-29T18:30:00Z",
"expiryDateStr": null,
"lastUpdated": "2012-02-10T10:20:06Z",
"securityCode": null,
"type": {
"enumType": "CreditCardType",
"name": "Visa"
},
"user": {
"class": "User",
"id": 4
}
}
}
I can't change server code, so how do i parse it. any helped..
your enum:
enum CreditCardType{
Visa, MasterCard, Diners
}
and while parsing, when you reach till type
//param is JSONObject
CreditCardType card = CreditCardType.valueOf(param.getString("name"));

Categories

Resources