1

I am building a Sencha touch 2 app.

I have a store that gets json data from a local php file.

This works fine when I run it on Google chrome (localhost). The List get populate with the correct data. However when i deploy the app to a android simulator the list doesn't get populated and LagCat shows the following message

0[WARN][Ext.data.reader.Reader#process] Unable to parse the JSON returned by the server: Error: You're trying to decode an invalid JSON String: <?php //Contents of the php file ?>

My store:

Ext.define('app.store.Info', {
    extend: 'Ext.data.Store',
    requires: [
    ],
    config: {
        model: 'app.model.info',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'getinfo.php',
            reader: {
                type: 'json'
            }
        }
    }
});

my php file uses json_encode to convert a array to json.

I know the php file is correct because it works when i test in Chrome. I am wondering if i have to do something special to run php in an Android app.

keshav
  • 866
  • 11
  • 19

4 Answers4

0

You can fetch json from anywhere around the web. Try this tutorial.

http://www.vogella.com/articles/AndroidJSON/article.html

Tapan Desai
  • 848
  • 2
  • 14
  • 36
0

I had similar issue few days back. In my case, the problem was with the way I parsed the JSON response String in my code. How are you parsing it?.Did you print the result String in Log cat and checked for any error codes, or some invalid string appended to it in the beginning.?

sugra
  • 73
  • 1
  • 6
0

I have two suggestions

  1. creating a web services to catch the JSON in the php from the Android

  2. Create a httpGet to hard code the link containing json file and decode it by Android

Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141
0

You cannot put PHP files inside Android and expect a JSON output. Because PHP interpreter is not working inside Android. However you can deploy the PHP file inside your computer (Apache) and refer it from Android.

retromuz
  • 809
  • 9
  • 26