簡體   English   中英

將http請求轉換為json

[英]Convert the http request to json

如何將此網址的響應轉換為json? 我得到了valueForUndefinedKey:]: this class is not key value coding-compliant for the key ANeighborhood.' NSLog(@"array 5656 = %@", array);轉義序列引起的錯誤NSLog(@"array 5656 = %@", array); 在下面的代碼中這是我嘗試過的。

 NSURL * url = [NSURL URLWithString:urlString];

    NSError *error;
    NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

    if(!error)
    {
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:Nil];

        NSDictionary *dict = [jsonDict valueForKey:@"ProspectReportResult"];

        NSString *jsonString = [NSString stringWithFormat:@"%@", dict];

        NSLog(@"String 444 = %@", jsonString);

        NSString *jsonString1=[jsonString stringByAppendingFormat:@"%s","]"];
        NSString *jsonString12=@"[";
        NSString *jsonString2=[jsonString12 stringByAppendingString: jsonString1];
        NSString *jsonString22=@"}{";
        jsonString2= [jsonString2 stringByReplacingOccurrencesOfString:jsonString22 withString:@"}][{"];

        NSLog(@"String 999 = %@", jsonString2);

        //jsonString2 = [jsonString2 stringByReplacingOccurrencesOfString:@"\\" withString:@""];
        NSArray *array12=[jsonString2 componentsSeparatedByString: @"]"];
        NSLog(@"Aray2323 = %@", array12);
        for(NSString* str in array12)
        {
            NSString *str1=[str stringByAppendingFormat:@"%s","]"];
            str1 = [str1 stringByReplacingOccurrencesOfString:@"\\" withString:@""];
            NSArray *array = [NSArray arrayWithObject:str1];
            NSLog(@"array 5656 = %@", array);

            for (NSDictionary *dict in array) {
                NSLog(@"Dictionary :%@",dict);
                prospect = [[ProspectData alloc]init];
                [prospectArray addObject:prospect];
                prospect.ANeighborhood= (NSString*)[dict valueForKey:@"ANeighborhood"];
                prospect.BClientName= (NSString*)[dict valueForKey:@"BClientName"];
                prospect.CSoldStatus=(NSString*)[dict valueForKey:@"CSoldStatus"];
                prospect.DFirstVisit=(NSString*)[dict valueForKey:@"DFirstVisit"];
                prospect.ELastVisit=(NSString*)[dict valueForKey:@"ELastVisit"];
                prospect.FNoOfVisit=(NSString*)[dict valueForKey:@"FNoOfVisit"];
                prospect.GTypeOfLead=(NSString*)[dict valueForKey:@"GTypeOfLead"];
                prospect.HPurchRealtor=(NSString*)[dict valueForKey:@"HPurchRealtor"];
                prospect.IClientSource=(NSString*)[dict valueForKey:@"IClientSource"];

            }

        }
        //[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
        [self.tableView reloadData];
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM