Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Error parsing JSON request string

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, what does the string being sent to the server look like? Have you checked it? Is it valid?
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
toJSONString is not part of JavaScript so I guess you should be including some 3rd party library.

Eric
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks valid to me.
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you,

the string is valid and i got it working.

my server code looks like this:

 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic