2012-06-07 29 views
2

我有这样的JSON:如何获取此JSON的交易信息?

{ 
    "status": true, 
    "1": { 
     "id": "1", 
     "deal": "Testing the mobile" 
    }, 
    "2": { 
     "id": "2", 
     "deal": "Testing" 
    }, 
    "3": { 
     "id": "3", 
     "deal": "Testing" 
    } 
}​ 

我怎样才能获得iddeal?我正在使用PhonegapjQuery Mobile

回答

2
var data = { 
    "status": true, 
    "1": { 
     "id": "1", 
     "deal": "Testing the mobile" 
    }, 
    "2": { 
     "id": "2", 
     "deal": "Testing" 
    }, 
    "3": { 
     "id": "3", 
     "deal": "Testing" 
    } 
}; 

data['1'].id; 

data['1'].deal; 

等等。

DEMO

使用jQuery $.each()循环:

$.each(data, function(key, val) { 
    if (key != 'status') { 
     alert(val.id); 
     alert(val.deal); 
    } 
}); 

DEMO

使用香草的Javascript

for(var key in data){ 
    if (key != 'status') { 
     alert(data[key].id); 
     alert(data[key].deal); 
    } 
} 

DEMO