PDA

View Full Version : Parsing Array in JSON?



Yser
15 Jul 2011, 12:44 PM
Hello,

I have a bit trouble with the JsonReader.

i have a json like this:

"responseData": {
"feed":{
"feedUrl":"http://www.digg.com/rss/index.xml",
"title":"digg.com: Top News",
"link":"http://digg.com/",
"author":"",
"description":"digg.com: Top News",
"type":"rss20",
"entries":[{
"mediaGroups":[{
"contents":[{
"url":"http://cdn2.diggstatic.com/story/city_vs_country_which_is_healthier/l.png",
"height":160,
"width":160},
{
"url":"http://cdn2.diggstatic.com/story/city_vs_country_which_is_healthier/s.png",
"height":48,
"width":48},
{
"url":"http://cdn1.diggstatic.com/story/city_vs_country_which_is_healthier/m.png",
"height":120,
"width":120},
{
"url":"http://cdn1.diggstatic.com/story/city_vs_country_which_is_healthier/t.png",
"height":62,
"width":62}
]
}],
"title":"City vs. Country: Which is Healthier?",
"link":"http://digg.com/news/lifestyle/city_vs_country_which_is_healthier",
"author":"",
"publishedDate":"Wed,
06 Jul 2011 06:16:54 -0700",
"contentSnippet":"Carrie Bradshaw and the rest of the crew from Sex and the City couldn't imagine a life outside of Manhattan.",
"content":"Carrie Bradshaw and the rest of the crew from Sex and the City couldn't imagine a life outside of Manhattan.",
"categories":[]}
]
}
},
"responseDetails": null,
"responseStatus": 200}so i wanna parse one feed out of it and thats just working fine with this(playin around with the googleapi):

rssreader.views.RSSReaderLists = Ext.extend(Ext.Panel, {
layout: 'fit',
dockedItems: [{
xtype: 'toolbar',
title: 'Title'
}],
items: [
new rssreader.views.RSSReaderInnerList({
store: new Ext.data.Store({
id: 'store_tp',
model: 'Entry',
autoLoad: true,
proxy: {
type: 'scripttag',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=-1&q=http://www.digg.com/rss/index.xml',
reader: {
type: 'json',
root: 'responseData.feed.entries'
}
}
})
})
]
});Now i wanna parse the images in every entry but i dunno how to put the array into my model.
I tried it with an association between entry and image...but that doesnt work :/


Ext.regModel("Entry", {
fields: [
/*{name: "image_url", type: "string", defaultValue: "http://www.nmh.ie/iopen24/images/content_images/other/warning.jpg"},*/
{name: "title", type: "string"},
{name: "link", type: "string"},
{name: "author", type: "string"},
{name: "contentSnippet", type: "string"},
{name: "content", type: "string"}
],
hasMany: {model: 'Image', name: 'images', mapping: 'mediaGroups.contents'}
});
Ext.regModel('Image', {
fields: [
{name: "url", type: "string"},
{name: "height", type: "int"},
{name: "width", type: "int"},
],
belongsTo: 'Entry'
});any idea how to get the images out of the json/ accessing the images?