2

I am very new to Android and I don't have a lot of knowledge about JSON parsing. I have tree structure JSON but am unable to parse and store it in class and I'm confused how to display on the UI.

Note: I have trying JSON Parsing Mannually, any libary for this, give me hints. ::: unable to fetching in ui , I want to fetch data in to stricky header view. Any idea, I have store separately subcategory1, 2,3,and 4 in different class as class list because i have just four subcategory every category.

Below is code snipped showing what i've done thus far, but i am not sure that works or not, could anybody help me with how to store data in java class and how to access and display it on UI.

UI Structure: Every Category as Stricky Top.(Problem: During Show data on This View)

Category1
     Sub Category 1
       data
     Sub Category 2
       data
     Sub Category 3
       data
     Sub Category 4
       data
Category2
     Sub Category 1
       data
     Sub Category 2
       data
     Sub Category 3
       data
     Sub Category 4
       data
.
.
.

I have JSON Data ,Structure Image, that i have json.https://i.stack.imgur.com/WvjJo.jpg JSON Data: Click Here enter image description here What i have done during parsing in android: I have added data on separate class for sub categories class like commclass, callsiclass, text class here.

Getting All ads in these list;

display all data same every category and subcategory. how to display respective data from class.

Thanks in advance. I'd appreciate if anybody could help out with the appropriate tricks parsing these type of JSON data in android.

Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
Bixms
  • 771
  • 1
  • 7
  • 16
  • 1
    Make a Pojo class with the same field names as is Json and then make an ArrayList of that pojo class type and add the json data in it. – Tushar Gogna Feb 19 '15 at 06:19
  • what problem you are getting with current code ? – ρяσѕρєя K Feb 19 '15 at 06:25
  • But Sir, I have not experience in using pojo class, could you give me some idea, how to use it. – Bixms Feb 19 '15 at 06:25
  • @ρяσѕρєяK, I have not display data properly on UI, every category have display all data but i want data display particular category and associate sub category with data. – Bixms Feb 19 '15 at 06:26

1 Answers1

1

A little tip on the way. If you get tired of doing the JSON-parsing manually you can use a library instead.

GSON is pretty good, https://code.google.com/p/google-gson/. With this library you only make a Java-class matching the JSON attributes, and GSON will automatically parse your JSON-input. See the URL for examples.

Even have a gradle dependency for easy add: http://mvnrepository.com/artifact/com.google.code.gson/gson/

'com.google.code.gson:gson:2.3.1'

Add the above to your build.gradle dependencies.

Kenneth
  • 3,957
  • 8
  • 39
  • 62
  • 2
    this should be a comment not an answer – SMR Feb 19 '15 at 07:01
  • The author asks several times about tips for JSON-parsing. "I'd appreciate if anybody could help out with the appropriate tricks parsing these type of JSON data in android." and "Note: I have trying JSON Parsing Mannually, any libary for this, give me hints." – Kenneth Feb 19 '15 at 08:21
  • Here, I am parsing manually, is that correct? asking. if i am doing correct, Please give me some idea, how to display on stricky top header list that data as respective category->subcategory. – Bixms Feb 19 '15 at 09:48
  • I don't have time to test if it is correct. I would rewrite it using GSON. For informasjon on sticky headers list, please see http://stackoverflow.com/questions/20713046/how-to-make-sticky-section-headers-like-ios-in-android – Kenneth Feb 19 '15 at 10:25
  • I already populated stricky header list, but data populated problem. – Bixms Feb 19 '15 at 10:50
  • Ok. Create a class that matches the JSON structure. As you might have done already. Then add GSON as a dependency in your Android proejct, in your build.gradle like this: "compile 'com.google.code.gson:gson:2.3". Once GSON is in place, use GSON: Gson gson = new Gson(); gson.fromJson(jsonString, Foo.class); As stated in the answer to this question giving a GSON example. – Kenneth Feb 19 '15 at 10:56