问题
I am new to Sencha Touch and I am trying to figure out the JSON call to WordPress. I am using the JSON-API-for-BuddyPress plug-in on WordPress on the server side.
http://www.erefer.me/api/buddypressread/groups_get_groups/?username=troy
{"status":"ok","groups":{"149":{"name":"Barakah Biz Network Referrals","description":"This group is for B.B.N members to send and receive their referrals online. This way all members have an online record of their referrals and no worries of losing pieces of paper. You can easily view your referrals and contact them while they are hot. You can also send referrals to other members that are tracked for prizes. \r\n\r\nTracking how much business we do with each other is the only way to determine how effective we are at supporting each other in building our communities businesses together. Members of this group but be member of BBN Network.","status":"public","creator":{"202":{"username":"bbnnetwork","mail":"victoria@bbnnetwork.org","display_name":"bbnnetwork"}},"slug":"barakah-biz-network-referrals","is_forum_enabled":false,"date_created":"2012-12-19 16:15:38","count_member":"4"},"57":{"name":"Troy\\'s Public List of Referral Partners","description":"List of referral partners that I share with the public.","status":"public","creator":{"1":{"username":"troy","mail":"troy@eRefer.Me","display_name":"troy"}},"slug":"troys-public-list-of-referral-partners","is_forum_enabled":false,"date_created":"2012-10-10 00:50:34","count_member":"2"},"40":{"name":"Austin RainMakers","description":"RainMakers of Austin Group ","status":"private"},"1":{"name":"Troy\\'s Private Network","description":"Troy\\'s Private Referral Network","status":"private"}},"count":4}
The Model:
Ext.define('eReferMe.model.Group', {
extend: 'Ext.data.Model',
config: {
grouper: function(record) {
return record.get('name')[0];
},
fields: ['id',
'name',
'description',
'status',
'creator',
'slug',
'is_forum_enabled',
'date_created',
'count_member'
],
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'http://www.erefer.me/api/buddypressread/groups_get_groups/?username=troy',
reader: {
type: 'json',
successProperty: 'status',
rootProperty: 'groups',
totalProperty: 'count'
}
}
}
});
The Store:
Ext.define('eReferMe.store.Groups', {
extend: 'Ext.data.Store',
config: {
group: true,
model: 'eReferMe.model.Group',
sorters: 'name',
grouper : function(record) {
return record.get('name')[0];
}
}
});
I think it might have to do with the way the ID is not set-up like the rest of the fields, but I'm not sure. What am I missing?
回答1:
JSONP requires a "wrapper" function around the response. In this case it will be passed as part of the request, something like callback=Ext.data.JsonP.callback1
See: parsererror after jQuery.ajax request with jsonp content type
来源:https://stackoverflow.com/questions/14597295/json-parsing-issue-between-sencha-touch-and-wordpress-buddypress-api