Hussein Hussein - 5 months ago 30
iOS Question

Parsing JSON with NSDictionary

I am working on an app which fetches data from a server. I convert this data to XML and then parse it using XMLDictionary. My problem is counting the number of objects inside the dictionary.

"finance_fee_collection" = (
{
amount = "790.00";
"due_date" = "2015-06-04";
name = "Third Payment";
},
{
amount = "790.00";
"due_date" = "2014-12-11";
name = "First Payment";
},
{
amount = "740.00";
"due_date" = "2015-07-06";
name = "third payment";
}
);


Counting the above number of objects yields 3, which is true. But counting the following also results 3.

"finance_fee_collection" = {
amount = "740.00";
"due_date" = "2015-07-06";
name = "third payment";
};


What I want is to count the number of "finance_fee_collection" items, such that the first one results 3 and the second one results 1. Is there anyway I can approach this goal?

Answer

The first one seems to be an array, the second a dictionary:

if([finance_fee_collection iskindOfClass:[NSDictionary class]]){
    count = 1;
} else {
    count = result.count;
}

something similar to this should work. :) hope it is helpful.

Comments