私はJSONを取得し、JSON辞書画像、名前、URLで取得します。しかし、私はJSON辞書にコメントを入れて、tableView
にリロードします。私はしようとしたが、null値を取得します。ですから、コメントを取得してtableviewで再読み込みする方法を手伝ってください。私のコードをチェックし、私が間違っている場所を教えてください。ありがとうございました。JSON Dictionaryを解決するには
MY JSON
(
{
image = "http://sixthsenseit.com/school/project/uploades/160223032210.png";
likes = 3;
name = "RADHIKA SAXENA";
url = "http://sixthsenseit.com/school/my-school/uploads/photo_1448551101.jpg";
},
{
comment = (
{
comment = q;
name = "";
},
{
comment = f;
name = "";
},
{
comment = ffgggggggg;
name = "";
},
{
comment = vcvg;
name = "";
},
{
comment = ggg;
name = "";
},
{
comment = aad;
name = "";
},
{
comment = anku;
name = "";
},
{
comment = gffgffg;
name = "";
},
{
comment = fggg;
name = "";
},
{
comment = vgghj;
name = "";
},
{
comment = ffgfh;
name = testing;
},
{
comment = bnVib;
name = "HARSHALI SHARMA";
}
);
}
)
のviewDidLoadのGet応答
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://sixthsenseit.com/school/project/ios/image_data.php"]];
//create the Method "GET" or "POST"
[request setHTTPMethod:@"POST"];
//Pass The String to server(YOU SHOULD GIVE YOUR PARAMETERS INSTEAD OF MY PARAMETERS)
NSString *userUpdate =[NSString stringWithFormat:@"pid=%@&uid=%@&",@"29",@"1000710017", nil];
//Check The Value what we passed
// NSLog(@"the data Details is =%@", userUpdate);
//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
//Apply the data to the body
[request setHTTPBody:data1];
//Create the response and Error
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSArray *json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&err];
NSLog(@"results == %@",json);
_name.text = [[json objectAtIndex:0]objectForKey:@"name"];
image = [[json objectAtIndex:0]objectForKey:@"url"];
NSURL *url = [NSURL URLWithString:image];
NSData *imageData = [NSData dataWithContentsOfURL:url];
_image.image = [UIImage imageWithData:imageData];
url = [[json objectAtIndex:0]objectForKey:@"image"];
NSURL *urls = [NSURL URLWithString:url];
NSData *imageDatas = [NSData dataWithContentsOfURL:urls];
_url.image = [UIImage imageWithData:imageDatas];
comment_ary = [json valueForKey:@"comment"];
テーブルビューメソッド
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [comment_ary count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"tableview cell");
CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"htrcell"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *getValues = comment_ary [indexPath.row];
cell.name.text=[NSString stringWithFormat:@"%@",getValues [@"name"]];
cell.comment.text=[NSString stringWithFormat:@"%@",getValues[@"comment"]];
return cell;
}
返されるJsonは2つのオブジェクト –
を持つ配列です。配列の2番目のオブジェクトを取得し、それを辞書として保存する必要があります。 –
その後、私は –