Loading local JSON issue with Sencha, PhoneGap and Android 4.0.3

This is just a little tip when trying to load local .json files using the Ext.data.Store ajax proxy type. The following code will work in Android 4.0.3+ but you need to be sure to add an extra couple lines to get it to work, noCache: false and enablePagingParams: false. Without those lines the code still works fine in Android 2.3.3 but for Android 4 and above, the ajax fails on loading local .json files because the requests url includes parameters added by Sencha.

Roads DataStore

Ext.define("Roads", {
    extend:"Ext.data.Store",
    requires:"Ext.data.proxy.LocalStorage",
    config:{
        fields: [
            { name: 'id', type: 'int' },
            { name: 'title', type: 'string' },
            { name: 'subtitle', type: 'string' }
        ],
        proxy:{
            type:'ajax',
            url:'resources/data/roads.json',
            reader:{
                type:'json',
                           noCache: false,
            enablePagingParams: false,
                rootProperty:'roads'
            }
        },
        listeners:{
            load:function (s, r) {
                console.log(r)
            }
        }
    }
});

roads.json

{"roads":[
    {
        "id":"i10",
        "title":"Interstate 10 Arizona",
        "subtitle":"Papago Freeway/Maricopa Freeway"
    },
    {
        "id":"i17",
        "title":"Interstate 17 Arizona",
        "subtitle":"Black Canyon Freeway"
    },
    {
        "id":"l101",
        "title":"Arizona State Route 101",
        "subtitle":"Loop 101"
    }
]}

References where the solution was found:

http://www.sencha.com/forum/showthread.php?190878-Android-local-json-store-not-loading

http://www.sencha.com/forum/showthread.php?162322-Sencha-Touch-2-PhoneGap-are-not-working-on-Android-4/page3

-Mister

JSON (Lite)

For a current Flex project we use JSON to transfer data between the application and the backend. Adobe Labs has a JSON serialization library called corelib that includes MD5 hashing, JSON, and other parsing tools.  What if you need just JSON for your Flex or Flash AS3 application development?

There is already a JSON ActionScript file for AS2 available at JSON.org. This file would be great for your older Flash projects and maybe some mobile application development.   Initially, I tried to convert this file to AS3, but then I figured someone probably already did this.   After some extensive searching and help from Lar (as always), we were able to locate a version of JSON that had been converted to AS3 for a project called VEGAS.      

There was no stand alone version of JSON for AS3, we had to extract the JSON pieces from the project files.  I did a little touch up for the error messaging, but it is essentially the same JSON for AS2, just updated to work with AS3.  In fact, it is by the same author, ekameleon.    

I am including all the links to the original source information as well as a stand alone version of the JSON AS3 ActionScript file and Flex Library file with the compiled SWC (called JSONLite).   The total size of the JSON AS3 file is 5KB!   

JSON AS3 (Flash/Flex)

JSON SWC (Flex)

To use the file just add the SWC to your Flex Library path.    In the MXML file, import the file and call to serialize/deserialize the same way you do with the corelib JSON SWC:

import com.serialization.json.JSON;

var dataString:String = JSON.serialize(object);

var obj:Object = JSON.deserialize(string);

I don’t support these files, I am just passing the information along and doing some experimentation with other JSON libraries. Also note that using the JSONLite SWC or class file file instead of the corelib file won’t significantly lighten your Flex applications. Flex only compiles the packages and class files you reference in your application from the library. So the post title is a bit misleading because you only shave off that 1KB. However, I have heard from others that this class file is faster than most other JSON parsers which does give it a slight advantage if speed is a concern.

-Mister