3

I am getting "Error #1132: Invalid JSON parse input" and cannot understand why.

My json is generated by php: json_encode($x). Output json if displayed in TextArea(flex) shows this:

{
   "title":"The Incredibles",
   "year":"2004",
   "type":"movie",
   "id":"9806",
   "imdb_id":"tt0317705",
   "rating":8.6,
   "tagline":"No gut, no glory",
   "overview":"Bob Parr has given up his superhero days to log in time as an insurance adjuster and raise his three children with his formerly heroic wife in suburbia. But when he receives a mysterious assignment, it\\'s time to get back into costume.",
   "runtime":115,
   "budget":92000000,
   "image":"http:\/\/cf2.imgobject.com\/t\/p\/w185\/jjAgMfj0TAPvdC8E5AqDm2BBeYz.jpg",
   "trailer":"rMfrFG_69zM"
}

I validated with several validators and all of them say it's valid json.

On the flex side I am trying to access json with this code:

JSON.parse(event.result.toString());

but get the error. Has anyone had this problem?

Edit 1:

It seems that the overview line is where the issue is but I dont understand why exactly since I used php json_encode which should escape things correctly...

1
  • it\\'s Should be it\'s if you want "it's". Commented Jul 28, 2012 at 22:38

4 Answers 4

3

The escape sequence of \\' appears to terminate the JSON.

it\\'s should be it\'s if you want "it's".

Since this JSON uses " for strings, it could just be: it's.

JSON:

{
   "title":"The Incredibles",
   "year":"2004",
   "type":"movie",
   "id":"9806",
   "imdb_id":"tt0317705",
   "rating":8.6,
   "tagline":"No gut, no glory",
   "overview":"Bob Parr has given up his superhero days to log in time as an insurance adjuster and raise his three children with his formerly heroic wife in suburbia. But when he receives a mysterious assignment, it\'s time to get back into costume.",
   "runtime":115,
   "budget":92000000,
   "image":"http:\/\/cf2.imgobject.com\/t\/p\/w185\/jjAgMfj0TAPvdC8E5AqDm2BBeYz.jpg",
   "trailer":"rMfrFG_69zM"
}
Sign up to request clarification or add additional context in comments.

3 Comments

I removed the php's addslashes() function so now it's just "it's" but like before I am getting "SyntaxError: Error #1132: Invalid JSON parse input." in flex. Code used: JSON.parse(event.result.toString())['title']. The reason for toString() is that it gives "1118: Implicit coercion of a value with static type Object to a possibly unrelated type String." otherwise. What am I missing? I tried hard coded var string with same json as above and it worked so I am guessing it has something to do with either toString() or the return type of "event.result"
I marked it as correct answer as it does answer the question but I hope you can look into the problem in the comment, Thanks.
In the end the issue was that I appended some text in php's echo when I thought I was doing it in actionscript's trace function.
2

Didn't know you have solved the problem or not, however I have had the same problem too, and today finally solved it, the problem was server side, the file which returned json string, was in UTF8 encoding I have converted it(by notepad++) to ANSI and everything working ))).

1 Comment

My issue was extra text appended in php file (for testing) when I meant to append in my flex application so it would not be parsed.. I dont think encoding itself has anything to do with your issue, it's likely that you had a character that json parses such as (/, [] etc...)
1

There is no problem with JSON and I know that the question has already an answer, but this answer is for those people who still face the following error message:

Syntax Error: Error #1132: Invalid JSON parse input.

It can be a matter of misfitting result format when it comes to the HTTPService options: Try the text or e4x format (they are the most convenient ones) and avoid the xml format which may introduce some extra characters to the JSON output triggering some errors.

Parse your data by using:

var temp_obj:Object = JSON.parse(event.result as String);

and trigger the JSON output by calling the HTTPService with the correct resultFormat:

resultFormat="text"

or

resultFormat="e4x"

Comments

0

Your JSON is valide and dont have any prob in it. Might be this would help you. In your result event update ur code with reference below.

    // Code
    var result:Object = JSON.parse( String(event.result) );
    trace( result['title'] );

1 Comment

This question was already answered 10 months ago. My problem was I was appending some debugging text at the end of json data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.