解析json成dic對象 -(void)fetchedData:(NSData*)responseData {//parse out the json dataNSError* error; NSDictionary* json =[NSJSONSerialization JSONObjectWithData:responseData //1 options:kNilOptions error:&error]; NSArray* latestLoans =[json objectForKey:@"loans"]; //2 NSLog(@"loans: %@", latestLoans); //3 } 把對象產生json string //build an info object and convert to json NSDictionary* info =[NSDictionary dictionaryWithObjectsAndKeys:[loan objectForKey:@"name"], @"who", [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"], @"where", [NSNumber numberWithFloat: outstandingAmount], @"what", nil]; //convert object to data NSData* jsonData =[NSJSONSerialization dataWithJSONObject:info options:NSJSONWritingPrettyPrinted error:&error]; //print out the data contents NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];