PDA

View Full Version : "Error: not well-formed" when reading JSON data in intro example



shethvoss
7 Apr 2012, 8:01 PM
Working through the examples in the MVC tutorial (http://docs.sencha.com/ext-js/4-0/#!/guide/application_architecture-section-7), and get an "Error: not well-formed" in the error console, pointing to the users.json file, and specifically the first opening brace.

The error occurs just after I remove the explicit data statement in the store class and add the proxy (see below). I tried changing the json data (e.g. {succces: true}) to pure JSON format with double quotes, etc. but to no avail.

Am stumped, would appreciate a clue to get going again. Thanks!




Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',


// data: [
// {name: 'Ed', email: 'ed@sencha.com'},
// {name: 'Tommy', email: 'tommy@sencha.com'}
// ]
// ,
autoLoad: true,


proxy: {
type: 'ajax',
url: 'data/users.json',
reader: {
type: 'json',
root: 'users',
successProperty: 'success'
}
}
});

Animal
7 Apr 2012, 10:21 PM
Well what does your users.json look like?

shethvoss
8 Apr 2012, 10:30 AM
Great question, thanks for the prompt reply. Shown below. I should have thought to include this at first. This is simply pasted this in from the example, though its possible that I've been staring at it so long I can't see an obvious difference from the tutorial code.


{
success: true,
users: [
{id: 1, name: 'Ed', email: 'ed@sencha.com'},
{id: 2, name: 'Tommy', email: 'tommy@sencha.com'}
]
}

Animal
8 Apr 2012, 3:07 PM
I think if native JSON is being used, it will be insisting upon



{
"success": true,
"users": [
{"id": 1, "name": 'Ed', "email": 'ed@sencha.com'},
{"id": 2, "name": 'Tommy', "email": 'tommy@sencha.com'}
]
}

shethvoss
9 Apr 2012, 5:46 AM
Doh! I had accidentally selected "Reload page in browser" from the IDE, resulting in the page running off the local file system (file://Users/me/Sites/mypage.html) rather than the server (http://localhost/~me/Sites/mypage.html).

Firefox was clearly able to read the content of the JSON file (the first line of the JSON file appeared in the error message) but the error message appeared to be about the content not being well formed, as opposed to being about the way in which the content was being accessed.

Thanks for the post, knowing it *should* work was helpful to force continued search for the deeper problem.