开发者

getting <null> when trying to parse JSON response

i have problem with getting <null> when trying to display a string on a UILabel or either on the console, here is my code step by step :

NSArray *array=[[request responseString]JSONValue];
for (int i=0; i<[array count]; i++) {
NSDictionary *stationEnCours=[array objectAtIndex:i];
NSLog(@"%@",[stationEnCours objectForKey:@"ssiphone_adresse"]);
}
topStation.sstationAdress=[stationEnCours objectForKey:@"ssiphone_adresse"]; //global variable
adresseStation.text=[NSString stringWithFormat:@"%@",topStation.sstationAdress];//display on label

Now for both the console and the label i got <null> although i have check it in my data base it's not null. is that due to JSON parsing rules ? how can i fix it ? thx in advance for help :) EDIT : here is my response string :

    2011-05-12 15:09:38.424 TopStation[1070:207] response string :[
{"ssiphone_idstation":"80","0":"80","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"Sans Plomb 95,SP95-E10,Gazole,GPLc,GNV,","4":"Sans Plomb 95,SP95-E10,Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"24h\/24","6":"24h\/24","ssiphone_telephone":"0400221997","7":"0400221997","ssiphone_sensdecirculation":"(Sens >> Aix-en-Prov.\/Marseille)","8":"(Sens >> Aix-en-Prov.\/Marseille)","ssiphone_adresse":"A 51 - Aire de la Champouse","9":"A 51 - Aire de la Champouse","ssiphone_ville":"BOUC-BEL-AIR","10":"BOUC-BEL-AIR","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.39532","12":"5.39532","ssiphone_latitude":"43.4416","13":"43.4416","ssiphone_nomstation":"RELAIS TOTAL DE LA CHAMPOUSE","14":"RELAIS TOTAL DE LA CHAMPOUSE","ssiphone_voie":"A 51","15":"A 51","ssiphone_enseigne":"TOTAL","16":"TOTAL","ssiphone_codepostal":"13320","17":"13320","ssiphone_referencegps":"TOTAL DE LA CHAMPOUSE A 51","18":"TOTAL DE LA CHAMPOUSE A 51","distance":17.3},
{"ssiphone_idstation":"86","0":"86","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"SP95-E10,Gazole,Super Gazole,GPLc,GNV,","4":"SP95-E10,Gazole,Super Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"24h\/24","6":"24h\/24","ssiphone_telephone":"0442591667","7":"0442591667","ssiphone_sensdecirculation":"","8":"","ssiphone_adresse":null,"9":null,"ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.43361","12":"5.43361","ssiphone_latitude":"43.5194","13":"43.5194","ssiphone_nomstation":"STATION BP","14":"STATION BP","ssiphone_voie":"","15":"","ssiphone_enseigne":"BP","16":"BP","ssiphone_codepostal":"13100","17":"13100","ssiphone_referencegps":"BP AIX EN PROVENCE","18":"BP AIX EN PROVENCE","distance":25.3},{"ssiphone_idstation":"89","0":"89","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"SP95-E10,E8开发者_如何转开发5,Gazole,Super Gazole,GPLc,","4":"SP95-E10,E85,Gazole,Super Gazole,GPLc,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":null,"6":null,"ssiphone_telephone":"0442264052","7":"0442264052","ssiphone_sensdecirculation":"(Centre ville) (A8 sortie 31)","8":"(Centre ville) (A8 sortie 31)","ssiphone_adresse":"467 Avenue Henri Mauriat","9":"467 Avenue Henri Mauriat","ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.4661","12":"5.4661","ssiphone_latitude":"43.5157","13":"43.5157","ssiphone_nomstation":null,"14":null,"ssiphone_voie":"","15":"","ssiphone_enseigne":"TOTAL","16":"TOTAL","ssiphone_codepostal":"13090","17":"13090","ssiphone_referencegps":"TOTAL DE L'ARC","18":"TOTAL DE L'ARC","distance":24.9},{"ssiphone_idstation":"91","0":"91","ssiphone_etatstation":"true","1":"true","ssiphone_commerce":"true","2":"true","ssiphone_stationdelavage":"false","3":"false","ssiphone_typescarburants":"Sans Plomb 95,Sans Plomb 98,Gazole,Super Gazole,GPLc,GNV,","4":"Sans Plomb 95,Sans Plomb 98,Gazole,Super Gazole,GPLc,GNV,","ssiphone_joursdelasemaine":"7J\/7","5":"7J\/7","ssiphone_horaires":"L-S: 7h30-20h","6":"L-S: 7h30-20h","ssiphone_telephone":"0442958459","7":"0442958459","ssiphone_sensdecirculation":"(Dir.>> Aix Ouest) ","8":"(Dir.>> Aix Ouest) ","ssiphone_adresse":"Route de Berre - Jas de Bouffan","9":"Route de Berre - Jas de Bouffan","ssiphone_ville":"AIX-EN-PROVENCE","10":"AIX-EN-PROVENCE","ssiphone_departement":"13","11":"13","ssiphone_longitude":"5.41778","12":"5.41778","ssiphone_latitude":"43.5342","13":"43.5342","ssiphone_nomstation":null,"14":null,"ssiphone_voie":"","15":"","ssiphone_enseigne":"CASINO","16":"CASINO","ssiphone_codepostal":"13090","17":"13090","ssiphone_referencegps":"CASINO AIX EN PROVENCE","18":"CASINO AIX EN PROVENCE","distance":27.1}]

EDIT:

the response is coded like this in the server side :

 $stationsFinales=array();
           $stationsFinales=$this->EpurationStations($stationsIdeales);

           sendResponse(200,json_encode($stationsFinales));
           return true;


I don't know JSON very well but when I used it in my application, I solved a problem like this by using valueForKey: instead of objectForKey: and try to use this code:

NSArray *array = [[request responseString] JSONValue];

for (int i = 0; i < [array count]; i++) {
    NSDictionary *stationEnCours = [array objectAtIndex:i];
    NSLog(@"%@", [stationEnCours valueForKey:@"ssiphone_adresse"]);
    topStation.sstationAdress = [stationEnCours valueForKey:@"ssiphone_adresse"];
}

adresseStation.text = [NSString stringWithFormat:@"%@", topStation.sstationAdress];

Consider this answer only as a test because, as I've said before, I don't know JSON very well.
However, I hope this can help you like me!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜