kcjoon / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

JSONParseError: Unexpected o encountered #119

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
bug free

What version of the product are you using? On what operating system?
latest,windows

Please provide any additional information below.

Original issue reported on code.google.com by varun.1...@gmail.com on 2 Sep 2009 at 6:05

GoogleCodeExporter commented 8 years ago
Please attach the JSON string you are trying to decode so we can identify the 
potential issue.  You might also 
want to try making sure the JSON string is valid by running it through the 
online validator at: 
http://www.jsonlint.com/

Original comment by darron.schall on 3 Sep 2009 at 2:11

GoogleCodeExporter commented 8 years ago

Original comment by darron.schall on 3 Sep 2009 at 2:11

GoogleCodeExporter commented 8 years ago
here's some code that gives this Error :

Original comment by mopic...@gmail.com on 20 Nov 2009 at 12:53

Attachments:

GoogleCodeExporter commented 8 years ago
I checked my JSON on jsonlint and it validates and I also get the unexpected o 
issue.
I searched for a word beginning with o that was not escaped properly and cannot 
find it.

Original comment by scitronp...@gmail.com on 7 Jan 2010 at 9:56

Attachments:

GoogleCodeExporter commented 8 years ago
Parsing works though if I use this construct instead:

var decoder:JSONDecoder = new JSONDecoder(resultString);
var resultObject:Object = (decoder.getValue() as Object);
var features:Array = new Array(resultObject["features"]);

Original comment by scitronp...@gmail.com on 7 Jan 2010 at 10:02

GoogleCodeExporter commented 8 years ago
I have also fallen into same situation. The only difference is that I am 
getting-
Unexpected j error.

I also have validated my JSON string using the tool provided.
Do we have some solution to it?

Original comment by rahul.sc...@gmail.com on 9 Feb 2010 at 11:59

GoogleCodeExporter commented 8 years ago
I had the same issue too, but I discovered the problem was that I didn't 
indicate in 
the "resultFormat" property of the HTTPService object as "text". I change this 
property to text and that error went away. Infact you don't have to use the 
method 
suggested by scitronpousty; just write your code the normal way: JSON.decode
(e.result.toString()).<json_data_field_name>.

Hope this helps someone.

Original comment by ugommiri...@gmail.com on 13 Apr 2010 at 12:34

GoogleCodeExporter commented 8 years ago
The workaround in #5 worked well for me for this exact error.

import com.adobe.serialization.json.JSONDecoder;

var decoder:JSONDecoder = new JSONDecoder(myJSONstring);
var myJSONobj:Object = (decoder.getValue() as Object);

Original comment by Benjamin...@gmail.com on 9 Jul 2010 at 10:01

GoogleCodeExporter commented 8 years ago
Kind of makes sense - I think the reason is that your thing is being passed as 
[object Object] , which is the string representation of your object. You're not 
getting the actual object itself. The unexpected o is the first o of [object].

Original comment by chu...@gmail.com on 24 Aug 2010 at 9:51

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
In my case this issue reproduced when I try to parse JSON where single quotes 
available. But when I replaced them by double quotes it resolved the problem.

Original comment by les...@gmail.com on 13 Apr 2011 at 9:01

GoogleCodeExporter commented 8 years ago
Make sure if your php files, that you dont use php short code such as <? - I 
was getting the error untill I replaced <? to <?php in all my using PHP 
HTTPSERVICE files. http://www.cteconsultants.net

I also copy the as3corelib in my libs folder of ech project 
my json results follow this path

private function getAllUsers():void{
 var _getAllUsers:HTTPService = new HTTPService();
 _getAllUsers.url = "[url path]";
_getAllUsers.method = 'POST';
_getAllUsers.addEventListener("result", getAllUsersResultHandler);

var params:Object = new Object();
 params.action = "getAllUsers";
 _getAllUsers.send(params);
}

private function getAllUsersResultHandler(e:ResultEvent):void{          
  var rawData:String = String(e.result); 
  var rawArray:Array = (JSON.decode(rawData) as Array); 
  au = new ArrayCollection(rawArray);
}

Original comment by mlow7...@gmail.com on 14 Nov 2011 at 5:17

GoogleCodeExporter commented 8 years ago
#5 saved me. I thought there was a problem with my base64 string that I made on 
the server from a file. 

Seems odd that I need to do this: "JSON.decode(data) as Object" when 
JSON.decode returns *. 

Doesn't * represent an Object type? Or does it simply mean any unknown type?

Original comment by keefepub...@gmail.com on 7 Apr 2012 at 7:10