Below is my sample JSON which I am getting from server I am using GSON annotation :-
{
"FAMILY": [{
"G": "0",
"Red": [{
"G": "89.5140282228858",
"B": "75.6247151421873",
"R": "190.744678043659"
}, {
"G": "159.384178987744",
"B": "142.476648231788",
"R": "237.397293369723"
}]
}, {
"G": "0",
"Blue": [{
"G": "89.5140282228858",
"B": "75.6247151421873",
"R": "190.744678043659"
}, {
"G": "159.384178987744",
"B": "142.476648231788",
"R": "237.397293369723"
}]
}]
}
You can use Map for parsing json with dynamic keys. this link might help you. which uses gson to parse json.
check this link also. check out the documentation of gson here.
Related
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.
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
}]
}]
}
I need help in making the result in group-by format through json array.
Below is my json array and I need to group-by records under "main" using json keys + values i.e. item_name and heat.
{
"results": {
"main": [
{
"id": "123",
"item_id": "234",
"entry": "1",
"item_name": "ASW 2-",
"event_type": "2-",
"heat": "Heat #1"
},
{
"id": "678",
"item_id": "789",
"entry": "1",
"item_name": "ASW 2-",
"event_type": "2-",
"heat": "Heat #2"
}]
}}
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"));
I'm working with android and gson and i was wondering if i can ignore a field from the webservice.
this its my gson object
Gson gson = new GsonBuilder().serializeNulls().create();
So what i need is to ignore validator field and deserialize to my custom bean in the following code.
Its any way to do that with gson ?
{ "posts":
[
{
"username": "John",
"message": "I'm back",
"time": "2010-5-6 7:00:34"
"validator":[{
"prog": "Name1",
"name": "Name2",
"computername": "Name3",
"date": "2010-11-20 19:39:55"
}]
}
,
{
"username": "Smith",
"message": "I've been waiting",
"time": "2010-4-6 10:30:26"
"validator":[{
"prog": "Name1",
"name": "Name2",
"computername": "Name3",
"date": "2010-11-20 19:39:55"
}]
}
]}
Thanks in advance
Cheers
You can call gson.fromJson(inputString, localObject) and if localObject doesn't declare a validator variable, it will just skip it.