开发者

How can i parse this JSON feed in Titanium Mobile App

开发者 https://www.devze.com 2023-04-02 11:20 出处:网络
How can i parse this JSON feed in Titanium Mobile App . { \"data\":{ \"mat_78\":{ \"id\":\"78\", \"title\":\"latest title here\",

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

......
.........


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


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消