-5

i am new in iphone development , i have an json response like :-`

(
    {
    0 = 1;
    1 = Pradeep;
    2 = "<null>";
    3 = "<null>";
    "friendship_flag" = "<null>";
    id = 1;
    name = Pradeep;
    sender = "<null>";
},
    {
    0 = 2;
    1 = Pradeep;
    2 = "<null>";
    3 = "<null>";
    "friendship_flag" = "<null>";
    id = 2;
    name = Pradeep;
    sender = "<null>";
},

i want to display all names on table view . my code like as:-

NSDictionary *allDataDictionary=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSLog(@"Data from Web %@",allDataDictionary);


NSArray *feedforentry=[allDataDictionary objectForKey:@"1"];

[array addObject:name]; //array will be display on table view .

Thanks in Advance .

4

4 回答 4

3

我认为您直接从响应中获取了数组,因此直接将响应分配给数组并在表格视图中显示名称,如下所示。

NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];

在 cellForRowAtIndexPath 方法中,您必须编写

NSDictionary *dictionary = [dataArray objectAtIndex:indexPath.row]; 
cell.textLabel.text=[字典 objectForKey:@"name"];
于 2013-09-11T06:37:17.910 回答
1

此代码用于在 Tableview 中显示您的数组数据...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{



   return [array count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //cell.selectionStyle=UITableViewCellEditingStyleNone;

    }

    NSDictionary *dictionary = [array objectAtIndex:indexPath.row];
    cell.textLabel.text=[dictionary objectForKey:@"name"];

    //cell.textLabel.text=[array objectAtIndex:indexPath.row];
    /
    return cell;
}
于 2013-09-11T06:37:19.047 回答
-1

获取数组中的所有名称,然后在您的 tableView 数据源方法 cellForRowAtindex 中执行此操作

cell.label.Text = [yourArray objectAtIndex:indexPath.row];
return Cell;
于 2013-09-11T06:39:08.533 回答
-1
NSArray *getArray=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];

    for (NSDictionary *dataDict in getArray){
        [array addObject:[dataDict objectForKey:@"name"]];
    }

    [yourTableView reloadData];

我想这会对你有所帮助。

于 2013-09-11T06:43:50.787 回答