wanna ask about json and dictioary also array
now i’ve json data like this
{
data: [
{
featured: true,
price: {
currency: "IDR",
amount: 5557679,
formatted: "Rp5.558.000"
},
]
}
and this is my syntax to call this
NSArray* deals_global_json = [json objectForKey:@"data"]; //2
if(deals_global_json!=NULL){
for (int i=0;i<[deals_global_json count];i++){
NSDictionary* jsonData = [deals_global_json objectAtIndex:i];
NSString *featured=[jsonData objectForKey:@"featured"];
NSArray *price=[jsonData objectForKey:@"price"];
NSDictionary *formatted =[price objectAtIndex:0];
}
and it error, how to parse price array like that?
This is wrong in your code:
because price is a Dictionary.
You can use:
The difference between {…} and […]:
the first one is Object (an unordered collection of key:value pairs with the ‘:’ character separating the key and the value, comma-separated and enclosed in curly braces; the keys must be strings and should be distinct from each other);
the second one is Array (an ordered sequence of values, comma-separated and enclosed in square brackets; the values do not need to be of the same type).
To understand, how it works, you can read more about JSON:
http://en.wikipedia.org/wiki/JSON