我如何在 Titanium 移动应用程序中解析此 JSON feed
我如何在 Titanium Mobile App 中解析此 JSON feed。
{
"data":{
"mat_78":{
"id":"78",
"title":"latest title here",
"teaser":"latest teaser here",
"body":"latest body here",
"logo":"http://sites/default/files/6_0.jpg",
"files":{
"323":{
"fid":"323",
"filename":"joudi1m.jpg",
"tumb":"http://sites/default/files/joudi1m_0.jpg",
"large":"http://sites/default/files/joudi1_0.JPG",
"caption":"joudi1m.jpg"
},
"471":{
"fid":"471",
"filename":"Shot-(0_00_15_09)m.jpg",
"tumb":"http://sites/default/files/Shot(0_00_15_09)m.jpg",
"large":"http://sites/default/files/Shot(0_00_15_09).jpg",
"caption":"Shot(0_00_15_09)m.jpg"
}
}
},
"mat_79":{
"id":"79",
"title":"latest title 2 here",
"teaser":"latest teaser 2 here",
"body":"latest body 2 here",
"logo":"http://sites/default/files/d09a0498a8512.jpg",
"files":{
"339":{
"fid":"339",
"filename":"BO1m.png",
"tumb":"http://sites/default/files/BO1_0.png",
"large":"http://sites/default/files/BO4_0.PNG",
"caption":"BO1m.png"
},
"340":{
"fid":"563",
"filename":"Slide9m.jpg",
"tumb":"http://sites/default/files/Slide9m.jpg",
"large":"http://sites/default/files/Slide9.JPG",
"caption":"Slide9m.jpg"
}
}
},
"mat_link":"mysite.cim/"
}
这是我用来解析 JSON 的代码段。但它没有得到......它给了我“未定义”
var loader = Titanium.Network.createHTTPClient();
loader.open("GET","http://mysite.com/data_iphone/en&lmt=5");
loader.onload = function()
{
var data = JSON.parse(this.responseData);
Ti.API.debug(data);
for (var i = 0; i < data.length; i++)
{
var my_id = data[i].id; // id
var my_title = data[i].title; // title
Ti.API.debug(my_title);
}
}
......
.........
How can i parse this JSON feed in Titanium Mobile App .
{
"data":{
"mat_78":{
"id":"78",
"title":"latest title here",
"teaser":"latest teaser here",
"body":"latest body here",
"logo":"http://sites/default/files/6_0.jpg",
"files":{
"323":{
"fid":"323",
"filename":"joudi1m.jpg",
"tumb":"http://sites/default/files/joudi1m_0.jpg",
"large":"http://sites/default/files/joudi1_0.JPG",
"caption":"joudi1m.jpg"
},
"471":{
"fid":"471",
"filename":"Shot-(0_00_15_09)m.jpg",
"tumb":"http://sites/default/files/Shot(0_00_15_09)m.jpg",
"large":"http://sites/default/files/Shot(0_00_15_09).jpg",
"caption":"Shot(0_00_15_09)m.jpg"
}
}
},
"mat_79":{
"id":"79",
"title":"latest title 2 here",
"teaser":"latest teaser 2 here",
"body":"latest body 2 here",
"logo":"http://sites/default/files/d09a0498a8512.jpg",
"files":{
"339":{
"fid":"339",
"filename":"BO1m.png",
"tumb":"http://sites/default/files/BO1_0.png",
"large":"http://sites/default/files/BO4_0.PNG",
"caption":"BO1m.png"
},
"340":{
"fid":"563",
"filename":"Slide9m.jpg",
"tumb":"http://sites/default/files/Slide9m.jpg",
"large":"http://sites/default/files/Slide9.JPG",
"caption":"Slide9m.jpg"
}
}
},
"mat_link":"mysite.cim/"
}
this is my code segment to parse the JSON . Bu its not getting .... its giving me 'undefined'
var loader = Titanium.Network.createHTTPClient();
loader.open("GET","http://mysite.com/data_iphone/en&lmt=5");
loader.onload = function()
{
var data = JSON.parse(this.responseData);
Ti.API.debug(data);
for (var i = 0; i < data.length; i++)
{
var my_id = data[i].id; // id
var my_title = data[i].title; // title
Ti.API.debug(my_title);
}
}
......
.........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信它应该更像这样
I believe it should be more like this
使用 onload 函数从您的服务器解析 jason
use onload function for parse jason from yor server