我如何在 Titanium 移动应用程序中解析此 JSON feed

发布于 2024-12-03 09:01:14 字数 2456 浏览 2 评论 0原文

我如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

跨年 2024-12-10 09:01:14

我相信它应该更像这样

    // NOTICE EXTRA "data" on end, if you are using JSON.parse()
    var data = JSON.parse(this.responseText).data;

    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); 
    }

I believe it should be more like this

    // NOTICE EXTRA "data" on end, if you are using JSON.parse()
    var data = JSON.parse(this.responseText).data;

    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); 
    }
注定孤独终老 2024-12-10 09:01:14

使用 onload 函数从您的服务器解析 jason

var loader = Titanium.Network.createHTTPClient();
var requstUrl = "your url";
loader.open("GET", requstUrl);
loader.onload = function() {


    var daysh = eval('(' + this.responseText + ')');
    var status = daysh.status;
    var jsonArry = daysh.locations;
    for (var i = 0; i < jsonArry.length; i++)
    {

        alert(i);

    }


};
loader.send();

use onload function for parse jason from yor server

var loader = Titanium.Network.createHTTPClient();
var requstUrl = "your url";
loader.open("GET", requstUrl);
loader.onload = function() {


    var daysh = eval('(' + this.responseText + ')');
    var status = daysh.status;
    var jsonArry = daysh.locations;
    for (var i = 0; i < jsonArry.length; i++)
    {

        alert(i);

    }


};
loader.send();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文