Still JSON error : "lexical error: invalid character inside string."

and I have an offset for the error, but I don’t see anything wrong there with textwrangler ?
what kind of error can it be ?
my json file is local, UTF8 encoded.

thanks.

Can you open the file in a hex editor and see if there are any control characters ?

yes - with xojo debugger, nothing wrong at the indicated offset, no control character. a simple string with a quote at the beginning and a quote at the end…

Encode the string has hex and post it here please. Are you using JSONItem or the new framework? If the former, can you try JSONItem_MTC to see if it’s still an issue?

https://github.com/ktekinay/JSONItem_MTC

Kem, the file is 14.6Mb long … hex encoded I’m pretty sure it wont fit here … :wink:
I use the new framework, it’s the only way I found to parse a json ?
I will try your MTC methods.
thanks.

It’s the only way on iOS, otherwise you can use the native JSONItem or my drop-in replacement. I recommend mine right now because 1) it fixes bugs found the in the native version and 2) it’s faster on non-Mac platforms than the new framework (I think that’s still true).

If you can and want to place that file somewhere, I’d be happy to play with it.

well, I made the json with another app and now it’s parsing ok.
as I don’t have time now to dig deeper, I will stop the search here, but Kem thanks for the help, as always !

Were you using 64 bit and String.Split() anywhere? that (was) buggy as hell and caused me some problems like what are you are saying.

The new ide versions doensn’t have this problem anymore.

The new framework can allow lossy in the encoding. I find it very easy to parse JSON with it. Can you show the conversion code of your Xojo.Data.ParseJSON etc?

[code]if inputFile<>nil then

Dim jsonString As String = inputFile.ReadAll(Encodings.UTF8)
Dim jsonText As Text = jsonString.ToText
if jsonText<>"" then

Dim recs() As Auto
dim res as Xojo.Core.Dictionary
res = Xojo.Data.ParseJSON(jsonText)
recs = res.Value("Data") //datas
...

[/code]

ReadAll is a method I made to extend it to the folderitem, and not only the textinputstream. same syntax.

no split and still 32 bits

the json source file I’m using comes from a bento model export. if you open the folder content of the generated file, you get a json file with all the bento database inside. I’m trying to import this into another database.
before that, I exported as a csv file, and used some converters that didnt work to transform them into json.
with the bento model file, it’s now ok xojo parses it correctly.

[quote=351281:@Jean-Yves Pochez][code]if inputFile<>nil then

Dim jsonString As String = inputFile.ReadAll(Encodings.UTF8)
Dim jsonText As Text = jsonString.ToText
if jsonText<>"" then

Dim recs() As Auto
dim res as Xojo.Core.Dictionary
res = Xojo.Data.ParseJSON(jsonText)
recs = res.Value("Data") //datas
...

[/code]

ReadAll is a method I made to extend it to the folderitem, and not only the textinputstream. same syntax.[/quote]

Ok It’s better if you use the new framework for all data reading code. It just works well together.

Dim MyJSONfile As FolderItem = SpecialFolder.Documents.Child("json.txt") 
Dim JSONFile As New Xojo.IO.FolderItem( MyJSONFile.NativePath )
Dim TIS As Xojo.IO.TextInputStream
Dim JSONText As Text
Dim res as Xojo.core.Dictionary

Try 
TIS = Xojo.IO.TextInputStream.Open( JSONFile, Xojo.core.TextEncoding.UTF8)
JSONText = TIS.ReadAll
Catch err As Xojo.Core.IOException
'Stop here and show message
Return
End Try

Try 
res = Xojo.Data.ParseJSON( JSONText )
Catch err As Xojo.Data.InvalidJSONException
'Stop here and show message (i quess this wont show unless your file is corrupted, say misplaced "{" or so)
Return
End Try

'res Dictionary is loaded use it.

Disclaimer; Untested code…:wink:

I’m currently using this with a Xojo.IO.BinaryStream and it works petty good. should work the same with Xojo.IO.TextInputStream as above.

[quote=351283:@Jean-Yves Pochez]the json source file I’m using comes from a bento model export. if you open the folder content of the generated file, you get a json file with all the bento database inside. I’m trying to import this into another database.
before that, I exported as a csv file, and used some converters that didnt work to transform them into json.
with the bento model file, it’s now ok xojo parses it correctly.[/quote]

It could be a simple endofline at the end or even beginning of the file.
Perhaps you may test if the first character is “{” and the last is “}” before loading it as a JSON file?

[quote=351375:@Derk Jochems]It could be a simple endofline at the end or even beginning of the file.
Perhaps you may test if the first character is “{” and the last is “}” before loading it as a JSON file?[/quote]
Or [ and ].