• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5623
  • Last Modified:

JSON Exception: Unterminated string at character

Hi There,

I received this exception while pulling all the data into JSON format.

net.sf.json.JSONException: Unterminated string at character 894195 .....

at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:512)
      at net.sf.json.util.JSONTokener.nextString(JSONTokener.java:244)
      at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:352)
      at net.sf.json.JSONArray._fromJSONTokener(JSONArray.java:1158)
      at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
      at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:358)
      at net.sf.json.JSONArray._fromJSONTokener(JSONArray.java:1158)
      at net.sf.json.JSONArray._fromString(JSONArray.java:1224)
      at net.sf.json.JSONArray.fromObject(JSONArray.java:149)
      at net.sf.json.JSONArray.fromObject(JSONArray.java:127)

any clues?

Please advice.

Thanks.
0
theartha
Asked:
theartha
  • 5
  • 4
  • 3
  • +1
3 Solutions
 
CEHJCommented:
Well - it's pretty clearly telling you what the error is ;) Please post the string
0
 
cmalakarCommented:
Can you please post the code snippet?
0
 
thearthaAuthor Commented:
@CEHJ: Data is huge and sensitive, is there any way that I can find out the 894195  th character.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
What os are you using?
0
 
thearthaAuthor Commented:
@CEHJ: Windows XP Professional
0
 
CEHJCommented:
You could put the string in a file and use an editor that shows the offset
0
 
thearthaAuthor Commented:
@CEHJ: I used editplus, but couldn't figure it out. Is there any better editor?
0
 
cmalakarCommented:
notepad++, textpad are other good text editors.
0
 
thearthaAuthor Commented:
@CEHJ,cmalakar:

I figured out the location:

["A","B","C","O","E","null","null"]

["A","B","C"," ","E","null","null"]

In the first JSON String at character "O", but in the second string at the same location. its empty string.
 because of that empty string I am getting an exception.

Please advice.
0
 
cmalakarCommented:
According to code for nextString() @ http://json-lib.sourceforge.net/xref/net/sf/json/util/JSONTokener.html

it throws an "unterminated string" syntax error only when the character matches either 0, or \n, or \r.
0
 
CEHJCommented:
It would probably be a good idea, not only to put the string in a file, but to use a JSON-aware editor on that file that can correctly indent it. It will making debugging a lot easier
0
 
objectsCommented:
> I figured out the location:

that doesn't sound like the location for that error. That string is fine.
you want to check the code the new line characters or nuls  as cmalakar mentioned above
you don't really want to be doing that in an editor, only takes a few lines of code to check

run this and let me know what it shows:

System.out.println(s.substring(894190, 8941200));
for (int i= 894190; i< 894200; i++) {
   System.out.println(i+":"+(int)s.charAt(i));
}
0
 
thearthaAuthor Commented:
Thanks guys.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now