aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Error parsing JSON request string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Error parsing JSON request string" Watch "Error parsing JSON request string" New topic
Author

Error parsing JSON request string

jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 124
I have the error : INFO: org.json.JSONException: A JSONObject text must begin with '{' at character 0

On netbeans 6.7.1, glassfish v3 prelude

On my client i create the json object and send it to GameServlet:



On the server side, i attempt to catch and parse:




Is there a simpler way to get and parse my json object on the server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56200
    
  13

Well, what does the string being sent to the server look like? Have you checked it? Is it valid?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 124
It would seem that it isn't:

line 27: on my client:
toJSONString() in the alert function did nothing.



the json_tank object and it's variables are fine, i checked that.

Is there a json javascript file (.js) that i must include in my header.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
toJSONString is not part of JavaScript so I guess you should be including some 3rd party library.

Eric
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 124
thank you,
toJSONString() is found in the json_parse.js file; available at JSON

I suppose the issue is: how do i call this function from within newjavascript.js

my HTML page has this in it's header:




BUT, and this is a major but; i came across this article which lead me to scrap using json_parse.js and use the toJSON(obj) function written by Tino Zijdel.

Bear Bibeault
Well, what does the string being sent to the server look like? Have you checked it? Is it valid?


thanks to Tino Zijdel's function,

Now my string looks like this: {"player_id":6123,"tank_id":0} ....checked and is this valid?

my error remains the same.




Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56200
    
  13

Looks valid to me.
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 124
thank you,

the string is valid and i got it working.

my server code looks like this:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error parsing JSON request string
 
Similar Threads
AJAX ( problem while retrieving xml data from the jsp)
responseXml is null
send data to swing from javascript
Notify Users before session expires
Rest based post for receiving and reponding with json