2

So I have a valid JSON string with Japanese characters but whenever I try and parse it I gets caught up on a specific character that it says is invalid.

Here's the offending string that's causing it. If you copy and past this and try to parse it, you get an error. You can also use JSONLint which will format it so it's easier to see

str = '{  "uuid": "214959c1-8f13-43e1-89a3-8ee1c891a118",  "token": "de45f7ca-00de-4c33-892e-ebcb0424ac2a",  "account": {    "type": "account",    "acoounts_id" : "123456",    "email" : "shinoda@timedia.co.jp",    "account_status_id" : "11",    "is_active" : true,    "region" : "JP",    "profiles": [      {        "type": "profile",        "profile_id": "4567",        "account_id": "123",        "first_name": "有里",        "last_name": "篠田",        "gender": "female",        "is_kids": false,        "language": "en",        "has_pincode": true,        "favorite_genres_selected": true,        "images": {          "profile_icon": {            "src": "http://icon.mypics.com/profile_4567.jpg"          }        }      },      {        "type": "profile",        "profile_id": "1234",        "account_id": "345",        "first_name": "高顕",        "last_name": "中野",        "gender": "male",        "is_kids": true,        "language": "ja",        "has_pincode": false,        "favorite_genres_selected": true,        "images": {          "profile_icon": {            "src": "http://icon.mypics.com/profile_4567.jpg"          }        }      }    ]  }}';
var parsed = JSON.parse(str);

And getting the error

Uncaught SyntaxError: Unexpected token (…)

Does anyone have any possible explanations? Any workarounds? The main issue is that I'm trying to return this as a response and without being able to convert it to an object the response type is all wonky.

I'm using a Node.js server running Express if that helps with providing any workarounds.

  • could you please post your exact code? – dm03514 Nov 03 '15 at 18:25
  • Hi, Can you please post the code you are trying and the error message you are getting? It's hard to debug when the code is not present. Thanks. – Nitin Nov 03 '15 at 18:27
  • As the other commenters have noted, you really need to post more code details.. If you construct a trivial code sample encoding your json as string, then parsing it, *things work fine*. You need to create a code sample illustrating the problem, preferably using a string literal as received from the server. – Paul-Jan Nov 03 '15 at 19:15
  • 1
    Alright I pasted the exact string it's returning that's causing the issue – Programmer Unextraordinair Nov 03 '15 at 20:12

1 Answers1

0

I did see this answer for parsing Japanese charters in JSON that may help you with your issue.

Basically you need to escape the charters before they are parsed into the object array.

Sending japanese characters over JSON

JSONObject info = new JSONObject();
info.put("japString", "よやかなゆひま".toString());
Community
  • 1
  • 1
Mallek
  • 122
  • 5