Viewed   128 times

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",
   "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.",

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:


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...



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.


   "title":"The Incredibles",
   "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.",
Wednesday, December 21, 2022

I would use xml for something like this, but it can be done with url encoded strings.

Assuming you loaded your data with URLLoader and specified the dataFormat as URLLoaderDataFormat.VARIABLES, you are close.

If you have a raw string, you should parse it first to break it down to name/value pairs. This is what URLVariables does.

Anyway, once you have an object containing names/values, you can do:

var i:int;
for (i = 0; i < 355; i++)
    var tempString:String = "vote" + i; 
    voteResults[i] =[tempString];

If you use dot access, it will take "tempString" literally. If you use bracket access, the value of the variable tempString will be evaluated.

PS: By the way, I don't think your php will do what you want. A cleaner way, IMO would be:

$pairs = array();
for ($i = 0; $i < 355; $i++)
    $pairs[] = 'vote' . $i . '=' . $votesArray[$i]; 
    // you might want to use rawurlencode($votesArray[$i]) to be safe if these are not numeric values.
echo implode('&',$pairs);

PS 2: Also, this is rather brittle since you're hardcoding 355. If you ever change your php, you'll have to change your AS code as well. You could try something like this:

var data:URLVariables = as URLVariables;
for(var fieldName:String in data) {
    var index:int = parseInt(fieldName.substr(4));
    //  or optionally, add an underscore to the name: vote_1
    //  so you can change the above to something like
    //  fieldName.split("_")[1]
    voteResults[index] = data[fieldName];

Or, as I said before, you could use xml, which is simple enough and a better option for this, I think.

Thursday, October 20, 2022

Multiple inheritance is not possible in AS. But with interfaces you can mimic some of the functionality of multiple inheritance. MI has major flaws, most notably the diamond problem: That's why many languages don't support MI, but only single inheritance. Using interfaces it "appears" you apply MI, but in reality that is not the case since interfaces don't provide an implementation, but only a promise of functionality.

interface BadAss{
    function doSomethingBadAss():void;

interface Preacher{
    function quoteBible():void;

class CrazyGangsta implements BadAss, Preacher{
    function quoteBible():void{
        trace( "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men." );
    function doSomethingBadAss():void{
        //do something badass

var julesWinnfield : CrazyGangsta = new CrazyGangsta();

//however, it mimics MI, since you can do:

var mofo : BadAss = julesWinnfield;
//but not mofo.quoteBible();

var holyMan : Preacher = julesWinnfield;
//but not holyMan.doSomethingBadAss();

P.S.: In case you'd wonder: There's no diamond problem with interfaces since an implementor of the interfaces must provide exactly one implementation of each member defined in the interfaces. So, even if both interfaces would define the same member (with identical signature of course) there will still be only one implementation.

Monday, December 19, 2022

Someone who has been coding with Flex daily for 2-3 years should have a pretty deep knowledge of the framework. They shouldn't just know how to use the framework but also how the framework itself works and how to extend it. If they don't, you probably don't want to hire them. :)

Advanced Flex developers should understand how UIComponent works and be able to explain the purpose of all these methods:

invalidateProperties / commitProperties
invalidateSize / measure
invaldiateDisplayList / updateDisplayList

getStyle / setStyle / clearStyle

They should know what the Flex "invalidation model" is and how it affects the "invalidate" methods and their counterparts. They should also be able to discuss a few of these topics:

  • How does container layout work? How does a Box container decide how to position and size its children?
  • How do Lists display their data and what makes item renderers special? How is a List different from a Repeater?

It's impossible to cover all of the things that a Flex dev should know in a short post here but having a deep understanding of UIComponent, its lifecycle and the invalidation model is super important.

Tuesday, December 27, 2022

To extend Amarghosh's answer, look to the constructor of ImageSnapshot

ImageSnapshot(width:int, height:int, data:ByteArray, contentType:String)

The data field isn't expecting BitmapData pixel data (bmp.getPixels), it's expecting data encoded in the given contentType. So you could do:

var encoder:PNGEncoder = new PNGEncoder();
var bytes:ByteArray = encoder.encode(bmp);
new ImageSnapshot(width, height, bytes, encoder.contentType);

Once you have to encode it yourself anyway, you should probably do away with the second ImageSnapshot reference and use:

new FileReference().save(bytes, "abc.png");
Wednesday, September 28, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :