Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Android- Parsing Local JSON Data (assets folder) (HELP)

 
ensar topbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making a test app with Android. I have a json file and i want to read it into activity class. The problem is that code doesn't get JSON data and write the data into the textView.
Here is the json file...



And here is the QuizActivityAdjectives.java file.



It doesn't get into the if (questions.size() > 0) block. Which means size is not bigger than 0. The size must be > 0 regarding upside codes. Can someone please help me?
 
Ron McLeod
Bartender
Pie
Posts: 1022
64
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JSON content is broken -- this JSON Online Parser might help. Also, the type of the id attribute in the JSON content and your application code do not match.

The JSON parser should have complained about both of these problems -- check the LogCat output.
 
ensar topbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:Your JSON content is broken -- this JSON Online Parser might help. Also, the type of the id attribute in the JSON content and your application code do not match.

The JSON parser should have complained about both of these problems -- check the LogCat output.


Should it be like this? And is it matching my parsing java code?
The id matter you if you mean having a letter and described as int, the id probably will not be necessary but does its being wrong effect the running and fetching json data question?

 
Ron McLeod
Bartender
Pie
Posts: 1022
64
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ensar topbas wrote:Should it be like this?

Well .. maybe -- you didn't show all of the JSON content, but adding a commas after the optionD values would have fixed the problem I saw.

For the id attribute, either change the JSON content so that id is a number, or leave it as-is and parse it as a String. Didn't you see something like this is the log?:

     W/System.err: org.json.JSONException: Value a200 at id of type java.lang.String cannot be converted to int
     W/System.err: at org.json.JSON.typeMismatch(JSON.java:100)
     W/System.err: at org.json.JSONObject.getInt(JSONObject.java:481)
 
ensar topbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:
ensar topbas wrote:Should it be like this?

Well .. maybe -- you didn't show all of the JSON content, but adding a commas after the optionD values would have fixed the problem I saw.

For the id attribute, either change the JSON content so that id is a number, or leave it as-is and parse it as a String. Didn't you see something like this is the log?:

     W/System.err: org.json.JSONException: Value a200 at id of type java.lang.String cannot be converted to int
     W/System.err: at org.json.JSON.typeMismatch(JSON.java:100)
     W/System.err: at org.json.JSONObject.getInt(JSONObject.java:481)


Thank you so much. I wouldn't ever expect but that id matter has been affecting the fetching process.
By the way, my logcat doesn't show me any error like you've written. Can i learn how could you get it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic