dear daniweb friends,
i really need help.
i want to parse a json from a file inside folder. that folder inside xcodeproj (not from URL).
i use this code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
/*NSData* kivaData = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://json.comli.com/reportTextEn.json"]
];*/
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"reportTextEn" ofType:@"json"];
NSError *error = nil;
NSData *kivaData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
NSDictionary* json = nil;
if (kivaData) {
json = [NSJSONSerialization
JSONObjectWithData:kivaData
options:kNilOptions
error:nil];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self updateUIWithDictionary: json];
});
});
-(void)updateUIWithDictionary:(NSDictionary*)json {
@try {
label1.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label1.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label2.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label2.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label3.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label3.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianPremi"],
nil];
label4.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label4.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"alokasiDanaInvestasi"],
nil];
label5.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label5.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianProduk"],
nil];
label6.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label6.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatAsuransiDasarA"],
nil];
label7.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label7.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"tertanggungUtama"],
nil];
label8.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label8.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"pertanggunganSampaiUsia"],
nil];
label9.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label9.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"uangPertanggunganDasarRp"],
nil];
label10.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label10.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiDasarRp"],
nil];
label11.font = [UIFont fontWithName:@"Arial-ItalicMT" size:8];
label11.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiNonInflation"],
nil];
label12.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label12.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"ringkasanManfaatRegular"],
nil];
label13.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label13.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"AsuransiDasarA"],
nil];
label14.font = [UIFont fontWithName:@"ArialMT" size:8];
label14.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"bilaTertanggungUtamaMeninggal"],
nil];
label15.font = [UIFont fontWithName:@"ArialMT" size:8];
label15.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatKhususJikaTertanggungUtamaMenderita"],
nil];
label16.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label16.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"ringkasanManfaatSingle"],
nil];
label17.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label17.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianProduk"],
nil];
label18.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label18.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label19.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label19.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianPremi"],
nil];
label20.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label20.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"alokasiDanaInvestasi"],
nil];
label21.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label21.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"tertanggung"],
nil];
label22.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label22.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"pertanggunganSampaiUsia"],
nil];
label23.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label23.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"uangPertanggunganRp"],
nil];
label24.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label24.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiRp"],
nil];
label25.font = [UIFont fontWithName:@"ArialMT" size:8];
label25.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"bilaTertanggungMeninggalDunia"],
nil];
label26.font = [UIFont fontWithName:@"ArialMT" size:8];
label26.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatKhususJikaTertanggungMenderita"],
nil];
label27.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label27.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatKhususPlatinum"],
nil];
label28.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label28.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"ringkasanManfaatSingle"],
nil];
label29.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label29.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"tertanggung"],
nil];
label30.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label30.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"pertanggunganSampaiUsia"],
nil];
label31.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label31.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"uangPertanggunganRp"],
nil];
label32.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label32.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiRp"],
nil];
label33.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label33.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label34.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label34.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianPremi"],
nil];
label35.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label35.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"alokasiDanaInvestasi"],
nil];
label36.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label36.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianProduk"],
nil];
label37.font = [UIFont fontWithName:@"ArialMT" size:8];
label37.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"bilaTertanggungMeninggalDunia"],
nil];
label38.font = [UIFont fontWithName:@"ArialMT" size:8];
label38.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatKhususTertanggungMeninggalDunia"],
nil];
label39.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label39.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label40.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label40.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianPremi"],
nil];
label41.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label41.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"alokasiDanaInvestasi"],
nil];
label42.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label42.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianProduk"],
nil];
label43.font = [UIFont fontWithName:@"ArialMT" size:8];
label43.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"tertanggung"],
nil];
label44.font = [UIFont fontWithName:@"ArialMT" size:8];
label44.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"pertanggunganSampaiUsia"],
nil];
label45.font = [UIFont fontWithName:@"ArialMT" size:8];
label45.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"uangPertanggunganRp"],
nil];
label46.font = [UIFont fontWithName:@"ArialMT" size:8];
label46.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiRp"],
nil];
label47.font = [UIFont fontWithName:@"Arial-ItalicMT" size:8];
label47.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiWithInflation"],
nil];
label48.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label48.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"ringkasanManfaatSingle"],
nil];
label49.font = [UIFont fontWithName:@"ArialMT" size:8];
label49.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"bilaTertanggungMeninggalDunia"],
nil];
label50.font = [UIFont fontWithName:@"ArialMT" size:8];
label50.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"manfaatKhususJikaTertanggungUtamaMenderita"],
nil];
label51.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label51.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"dataTertanggung"],
nil];
label52.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label52.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianPremi"],
nil];
label53.font = [UIFont fontWithName:@"Arial-BoldMT" size:9];
label53.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"alokasiDanaInvestasi"],
nil];
label54.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label54.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"rincianProduk"],
nil];
label55.font = [UIFont fontWithName:@"ArialMT" size:8];
label55.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"biayaAsuransiNonInflation"],
nil];
label56.font = [UIFont fontWithName:@"Arial-BoldMT" size:8];
label56.text = [NSString stringWithFormat:
@" %@",
json[@"halaman1"][@"ringkasanManfaatSingle"],
nil];
}
@catch (NSException *exception) {
[[[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not parse the JSON feed."
delegate:nil
cancelButtonTitle:@"Close"
otherButtonTitles: nil] show];
NSLog(@"Exception: %@", exception);
}
}
i put it in file abal.m
and in abal.h i call all label.
from uilabel inside viewcontroller, i drag+control to label in abal.h to get it appear on label text, but it only show blank label. and did not shown any error.
how to make it (the text from json) appear on label?
regards.