Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Where to download org.json.* ?

 
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The app is trying to get the data returned from an SQL query into a JSON string.
This is java on eclipse, not Android.

Should I use the JSON download from Google?
 
AhFai Chan
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I downloaded it from java2ws and it seems to be working.

The only problem is, my Android code works find, but my java code throws a JSONParseException:

JSON parsing error: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

Wonder whether the Google/Android json jar is the same as the java json jar.
 
Saloon Keeper
Posts: 2750
359
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

AhFai Chan wrote:JSON parsing error: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]


It looks like the JSON representation has problems - if it an object, it should be enclosed in { }.

Where is the JSON string data coming from?  Can you post what it looks like here?
 
Ron McLeod
Saloon Keeper
Posts: 2750
359
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple example:
 
AhFai Chan
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:

AhFai Chan wrote:JSON parsing error: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]


It looks like the JSON representation has problems - if it an object, it should be enclosed in { }.
Where is the JSON string data coming from?  Can you post what it looks like here?



The JSON string was a SQL result set encoded in JSON from the execution of a PHP script on the cloud MySQL database.
Android accepts the JSON string and parses it correctly, but java seemingly doesn't, hence my question whether the Android JSON and Java JSON are the same.

This is the code snippet from the loginhelper class, it simply executes the PHP script in JSON format:


And this is the login activity that calls the helper class:

 
AhFai Chan
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to plug the JSONObject into a HashMap and see what comes out the other end...
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlike in JavaScript objects, in JSON properties must be enclosed in "" as well. {name: "Maria"} is not valid JSON; {"name": "Maria"} is.
 
AhFai Chan
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:Unlike in JavaScript objects, in JSON properties must be enclosed in "" as well. {name: "Maria"} is not valid JSON; {"name": "Maria"} is.




OK, thanks, this is what the raw JSON string looks like (data value changed to protect the quilty , before parsing...

{"db_response":[{"User_ID":"12345","User_Name":"Arthur Chan","Farm_ID":"30","Mobile_Phone":"1234567890"}]}

As we can see, the first char is "{" followed by ", it shouldn't be that difficult to unpack it...
 
AhFai Chan
Ranch Hand
Posts: 179
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:Unlike in JavaScript objects, in JSON properties must be enclosed in "" as well. {name: "Maria"} is not valid JSON; {"name": "Maria"} is.



Oh cricky, this really sucks. See line 8 in login activity ?



See that "$, it should be "&".

And I have done hours of modifications to the codes, all of which works but for the "$"

Thanks all, can close this thread.
 
Ron McLeod
Saloon Keeper
Posts: 2750
359
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:Unlike in JavaScript objects, in JSON properties must be enclosed in "" as well. {name: "Maria"} is not valid JSON; {"name": "Maria"} is.


Thanks for pointing that out.
 
Look ma! I'm selling my stuff!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!