我想包含由NSString的类型和NSMutableArrays的联络信息对象的读取JSON文件。 目前,我使用的NSData读取整个文件,然后通过它解析。 我已经使用了Stig的例子这里提到: SBJson4Parser例
SBJson4ValueBlock block = ^(id obj, BOOL *stop) {
NSLog(@"Found: %@", @([obj isKindOfClass:[NSDictionary class]]));
//contactsData *contact = obj;
NSDictionary *contact = obj;
NSLog(@"Contact: %@",contact);
/* NSString *fName, *lName;
fName = [contact objectForKey:@"mFirstName"];
lName = [contact objectForKey:@"mLastName"];
NSLog(@"First Name: %@",fName);
NSLog(@"Last Name: %@",lName);
*/
};
SBJson4ErrorBlock eh = ^(NSError* err){
NSLog(@"Oops: %@",error);
};
NSLog(@"Parse work");
id parser = [SBJson4Parser multiRootParserWithBlock:block
errorHandler:eh];
//uint8_t buf[1024];
//unsigned int len = 0;
NSLog(@"Trying to push stream to data");
//[inputStream read:buf maxLength:len];
NSData *data = [NSData dataWithContentsOfFile:filePath options:NSUTF8StringEncoding error:NULL];
//id data = [json da:NSUTF8StringEncoding];
SBJson4ParserStatus status = [parser parse:data];
NSLog(@"Status: %u",status);
这些天,人们似乎有数百甚至数千的联系人,这要归功于社交网络。 这将导致在iOS设备上更大的内存占用? 如果是这样,我怎么解析来自流中的单个对象? 如果非要用一个代表,一个例子将不胜感激。
请注意,我是新来的iOS开发的世界以及Objective-C的。
The structure of the json file in question:
{
"mAddresses": [
],
"mContactPhoto": "",
"mDisplayName": ",tarun,,,,israni,,",
"mPhoneNumberList": [
{
"mLabel": "_$!<Home>!$_",
"mNumber": "(988) 034-5678",
"mType": 1
}
]
}{
"mAddresses": [
],
"mContactPhoto": "",
"mDisplayName": ",Sumit,,,,Kumar,,",
"mPhoneNumberList": [
{
"mLabel": "_$!<Home>!$_",
"mNumber": "(789) 034-5123",
"mType": 1
}
]
}