JSON Analysis: Unexpected Marker Error

I am trying to parse a string in JSON and I am getting an unexpected marker error.

I validate using http://json.parser.online.fr/ , which does not contain parsing errors, but still says that eval fails due to an unexpected token. If you embed JSON from the bottom of the site, you can see that it has detected an error, but does not indicate which token is causing it.

This is what I am trying to make out.

{ "Polish": { "Rent": [ { "english": "a", "audioUrl": "b", "alternate": "c" }, { "english": "d", "audioUrl": "e", "alternate": "f" } ] } } 

Am I missing something obvious?


EDIT
There is a non-printable character between: and [after the "Rent" key.

I make replace () calls on a line before trying parsing, which probably creates the problem.

before parsing this particular line

 "Rent":"[ 

I want to remove doublequote between: and [sybmols.

So, I use:

 var reg = new RegExp('":"', 'g'); var newStr = originalStr.replace(reg, '":'); 

I do not know why the above causes a non-printable character.


EDIT2
I did a quick check by deleting the Above replace () call, pasted it into the validator, manually deleted the double quotes that I used replace (), and the unreadable characters are still there. Therefore, an error is present in the source line. So, more code: |

The string is returned from an ajax call to a php script located on the server. The PHP script reads the directory on the server and populates the nested associative array to create a string that is sent back to the JS side, which edits and parses it (shown above).

Inside the directories are JSON files into which I paste the contents of this nested array structure to complete the JSON hierarchy.

Unreadable characters were

ef bb bf

What I searched on google and found the Byte Order Mark line representing the contents of the file.

Thus, the PHP code reads directories and JSON files, creating the structure of nested arrays as JSON_encode () d and is sent back to JS

 if ($langHandle = opendir($langDir)) { while (false !== ($langEntry = readdir($langHandle))) { $currentLangDir = $langDir . "/" . $langEntry; if (is_dir($currentLangDir) && $langEntry != '.' && $langEntry != '..') { $currentLang = array(); if ($currentLangHandle = opendir($currentLangDir)) { while (false !== ($catEntry = readdir($currentLangHandle))) { $currentCatFile = $currentLangDir . "/" . $catEntry; if(is_file($currentCatFile) && $catEntry != '.' && $catEntry != '..') { $currentCat = file_get_contents($currentCatFile); $currentLang[removeFileExtension($catEntry)] = $currentCat; } } } $langArray[$langEntry] = $currentLang; } } 

What can I do to fix these unwanted characters, a quick search to delete specification characters indicates that it is bad.

+4
source share
2 answers

You probably have a non-printable character that does not appear in what you inserted into your question. I copied and pasted your text into the online parser at the link you provided, and it parses cleanly.

Try copying and pasting the source code into this website with a hex dump and compare with what you get when you copy and paste the SO Question above ... if they differ, then you will understand where the dummy character is.

Here is a screenshot of the result I got that analyzes purely.

enter image description here

+5
source

Bro, I had a similar problem, check the encoding of your file (UTF-8) and (UTF-8 WITHOUT BOM) can make a difference.

0
source

All Articles