Due to the background of metamorphosis, sometimes there will be two layers or even multi-layered nested JSON package.
The first layer of the good solution, and I have seen some of the larger website News the JSON package returned by the interface is just a layer.
For example, the package shown on the layer
The code is simple and intuitive.
Dict = [data objectfromjsondata];//This could be a conversion failure, and then it needs to be judged._dinnarray=[[Nsmutablearray alloc] init]; _dataarray= [Dict Objectforkey:@"Data"]; for(Nsdictionary *dinndictinch_dataarray) {Service*servic =[Service Alloc]init]; Servic.name= [Dinndict Objectforkey:@"names"]; Servic.time= [Dinndict Objectforkey:@"Server_time"]; Servic.tel=[Dinndict objectforkey:@ "Tel"]; [_dinnarray Addobject:servic]; }
It's easy to read _dinnarray.
Service *service = [_dinnarray objectAtIndex:indexPath.row];
Two layers of nesting, read a lot of online posts, will be wrong.
For the package as shown
The code does not emphasize the point for the time being today. Just stick it down there.
Dict =[Data objectfromjsondata]; _dataarray= [[Dict objectforkey:@"Data"]retain]; for(nsdictionary*scourdictinch_dataarray) {_listarray=[scourdict Objectforkey:@"tel_list"]; Nsmutablearray*scourarray=[[Nsmutablearray alloc]init]; //NSLog (@ "Scorearray remove%@", scourarray); for(nsdictionary*listdictinch_listarray) { //NSLog (@ "Listdict%@", listdict); //NSLog (@ "listdict count%d", [listdict Count]);address*address=[Address Alloc]init]; Address.namelist=[listdict Objectforkey:@"name_contacts"]; Address.phone=[listdict Objectforkey:@"Phone_number"]; [Scourarray addobject:address]; } [_fourarray Addobject:scourarray]; }
Reading the array part
_adressarray=[_fourarray objectAtIndex:indexPath.section]; Address*address=[_adressarray ObjectAtIndex:indexPath.row];
The point is that in the existing section, the Scourarray must be a local variable, otherwise it can only store the last set of data, and the front will be overwritten.
In addition, read the part, to set two layers to read out the array. This is similar to the workaround for a two-dimensional array. A two-dimensional array is stored, and a two-dimensional array is read and read.