How to Parse Language other than English in json android - android

Anybody knows how to parse the "title" content in this JSON fromat ?
JSON:
{
"news": [
{
"Id": "58710",
"c_id": "6",
"title": "റയില്‍വേയില്‍ നിക്ഷേപം നടത്താന്‍ എല്‍ഐസി",
"image": "http://4malayalees.com/malayalamNews/thumb/58710.jpg",
"news": " വ്യത്യസ്ത പദ്ധതികള്‍ക്കായി അടുത്ത അഞ്ച് വര്‍ഷത്തിനുള്ളില്‍ എല്‍ഐസി റെയില്‍വേയ&"
},
{
"Id": "58551",
"c_id": "6",
"title": "മലയാളിയുടെ ന്യൂസ് പോര്‍ട്ടല്‍ ഇനി റൂപര്‍ട്ട് മര്‍ഡോക്കിന് സ്വന്തം",
"image": "http://4malayalees.com/malayalamNews/thumb/58551.jpg",
"news": "സഹദ് എന്ന പേര് ഒരുപക്ഷെ മലയാളികള്‍ക്ക് സുപരിചിതമല്ലായിരിക്കാം, എന്നാല്‍ മാധ്യമ ő"
}
]
}
Thanks in advance

Related

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.

how to read this JSON format [duplicate]

This question already has answers here:
How do I parse JSON in Android? [duplicate]
(3 answers)
Closed 4 years ago.
My JSON:
[
{
"productid": "3",
"name": "Potato",
"price": "15",
"quantity": "",
"stock": "0",
"description": "Fresh and good",
"image1": "upload/Potato1.jpg",
"image2": "upload/Potato2.jpg",
"image3": "upload/Potato3.jpg",
"status": "Out of Stock",
"type": "Vegetables"
},
{
"productid": "5",
"name": "Tomato",
"price": "25",
"quantity": "",
"stock": "45",
"description": "Fresh and good",
"image1": "upload/Tomato1.jpg",
"image2": "upload/Tomato2.jpg",
"image3": "upload/Tomato3.jpg",
"status": "Avaiable",
"type": "Vegetables"
},
{
"productid": "4",
"name": "Onion",
"price": "30",
"quantity": "",
"stock": "50",
"description": "Fresh and good",
"image1": "upload/Onion1.jpg",
"image2": "upload/Onion2.jpg",
"image3": "upload/Onion3.jpg",
"status": "Avaiable",
"type": "Vegetables",
"wishlistid": "43",
"userid": "10",
"flag": "1"
},
{
"productid": "6",
"name": "Carrot",
"price": "20",
"quantity": "",
"stock": "50",
"description": "Fresh and good",
"image1": "upload/Carrot1.jpg",
"image2": "upload/Carrot2.jpg",
"image3": "upload/Carrot3.jpg",
"status": "Avaiable",
"type": "Vegetables",
"wishlistid": "47",
"userid": "10",
"flag": "1"
}
]
In this first 2 json object have few column missing like userid and wishlistid and flag and remaining are having the userid, wishlistid and flag.
How can I read this with retrofit library .. because it gives me nothing as there is no userid column found in the first 2 objects.
You can parse json tow way one is manual or other using parser like Gson, Also better for both you create pojo class which help you.
String yourJsonString=jsondata;
JSONArray jsonArray= null;
try {
jsonArray = new JSONArray(yourJsonString);
if(jsonArray!=null && jsonArray.length()>0){
//Here you can parse tow way one is manual or other one using gson
//1.Manual one
for(int pos=0;pos<jsonArray.length();pos++){
JSONObject jsonObject=jsonArray.getJSONObject(pos)
//Here you can parse your object tow one is pass all value by manual
//like YourModelObject.setMethod(jsonObject.getString("keyName");
//Or other one is create model class and parse data using gson like following
/*CustomModel modelObj= new Gson().fromJson(jsonObject, new TypeToken<LocationHoModel>() {
}.getType());*/
}
//2.Using Gson
/*ArrayList<CustomModel> customModelArrayList = new Gson().fromJson(jsonArray, new TypeToken<ArrayList<CustomModel>>() {
}.getType());*/
}
} catch (JSONException e) {
e.printStackTrace();
}

How to parse json with dynamic keys using Retrofit 2.0?

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"
}]

Json Data Filteration according to category

I want to know how to filter data. I got data with category name but cannot filter category wise.Here is my data:
{
"TITLE": "tea",
"PRICE": "17",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Coffee",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
{
"TITLE": "Jeera chachh",
"PRICE": "42",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Roti Ghee Wali",
"PRICE": "21",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Paneer paratha",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
{
"TITLE": "Mix paratha",
"PRICE": "102",
"QTY": "1",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
I already parse the data but not able to set in fragment according to category.Can anyone solve my issue.
Step 1: Store the data in database.
Step 2: Search
select * from table where CAT_NAME = 'your_filter_category'.
or better ....CAT_NAME like %your_filter_category%.
In Case of no database;
Store the Data in list.
HashMap<String, ArrayList<Item>> map = new HashMap<>();
ArrayList<Item> itemList = new ArrayList<>();
Loop on List{
Item item = fromLoop index;
if(map.contains(item.getCat())){
itemList = map.get(item.getCat());
itemList.put(item);
map.put(item.getCat(),itemList);
}else{
itemList.clear();
itemList.put(item);
map.put(item.getCat(),itemList);
}
}
//after loop you will get HashMap with keys as categories and Values as the list of selected key category.
Step 3: Publish the results.
Note: No one will do your homework here. the only thing we can do for you, we can assist you how to do.
enter your code to: JSON Formatter and you will see that something is invalid in your JSON, it has multiple root elements. Maybe you should store whole code in JSONArray like this: `
{
"features":
[{
"TITLE": "tea",
"PRICE": "17",
"QTY": "1",
"CAT_ID":"33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg" },
{
"TITLE":"Coffee",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME":"MORNING SPECIAL",
"TYPE": "veg"
}]
}

How to fetch data through jsons?

I want to know that how can i fetch data through j sons. I.I am creating like this but did not get any data?
"arr": [1]
0: {
"obj": {
"id": "24"
"dispensary_id": "24"
"item_name": "item 3"
"total_feedback": "1"
"total_item": "13"
"followers": "7"
"follow_status": "following"
"category": "Edibles"
"strain": "Indica"
"tch": "0.70"
"cbd": "13.30"
"description": "testing items"
"image": "1447508911_greenfeed-3.jpg"
"qty1": "1/8 OZ"
"price1": "100"
"qty2": "1/4 OZ"
"price2": "200"
"qty3": "1/2 OZ"
"price3": "400"
"qty4": "1 OZ"
"price4": "799"
"dispensary_first_name": "Acme Dispensary"
"dispensary_last_name": "Smith"
"company": "Acme Dispensary"
"dispensary_image": "1449182412.png"
"city": "Irvine"
"state": "CA"
"status": "1"
}-
}-
-
"result": "true"
}
Use gson library for parsing JSON data. To learn how to use it go through with this link http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
your JOSN format is wrong it should be like this
{
"obj": {
"id": "24",
"dispensary_id": "24",
"item_name": "item 3",
"total_feedback": "1",
"total_item": "13",
"followers": "7",
"follow_status": "following",
"category": "Edibles",
"strain": "Indica",
"tch": "0.70",
"cbd": "13.30",
"description": "testing items",
"image": "1447508911_greenfeed-3.jpg",
"qty1": "1/8 OZ",
"price1": "100",
"qty2": "1/4 OZ",
"price2": "200",
"qty3": "1/2 OZ",
"price3": "400",
"qty4": "1 OZ",
"price4": "799",
"dispensary_first_name": "Acme Dispensary",
"dispensary_last_name": "Smith",
"company": "Acme Dispensary",
"dispensary_image": "1449182412.png",
"city": "Irvine",
"state": "CA",
"status": "1"
}
}
for this you can check on whether your json is valid or not http://jsonlint.com/
for creating json you can use some library like
JSONObject jsonObject = new JSONObject();
jsonObject.add("key", "value");
jsonObject.add("key", "value");

Categories

Resources