閱讀控制檯的JSON值我已經在控制檯下面的JSON值:如何在iphone
{"TokenID":"kuiHigen21","isError":false,"ErrorMessage":"","Result":[{"UserId":"153","FirstName":"Rocky","LastName":"Yadav","Email":"[email protected]","ProfileImage":null,"ThumbnailImage":null,"DeviceInfoId":"12"}],"ErrorCode":900}
這是我的服務器API:@「http://192.168.0.68:91/JourneyMapperAPI?RequestType =登錄「 // api需要5個參數。 當我發佈數據到服務器的api值發佈到服務器,我得到了以json格式的上述響應。
我想解析上述JSON值,我得到的響應和保存在sqlite數據庫。
我這樣做代碼分析上面的JSON值:
-(void)connectionDidFinishLoadingNSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] lengthwebData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",loginStatus);
self.webData = nil;
SBJSON *parser =[[SBJSON alloc]init];
NSURLRequest *request = [NSURLRequest requestWithURLNSURL URLWithString"http://192.168.0.68:91/JourneyMapperAPI?RequestType=Login.json"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
//NSDictionary *object = [parser objectWithString:json_string error:nil];
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
NSArray *statuses = [parser objectWithString:json_string error:nil];
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
NSLog(@"%@ - %@", [status objectForKey"Login"],[status objectForKey"LoginKey"]);
[connection release]; [webData release];
}
什麼問題? – deanWombourne 2011-06-14 11:00:12
hi @deanWombourne,這是我的JSON文件apitest [18318:207] {ErrorCode = 900; ErrorMessage =「」;結果=({DeviceInfoId = 12; Email =「[email protected]」; FirstName = Rocky; LastName = Yadav; ProfileImage =「」; ThumbnailImage =「」; UserId = 153;}); TokenID = 59nUniliob; isError = 0; }請你解釋一下如何解析上面的JSON文件,並將值保存在sqlite數據庫中 –
Rocky
2011-06-15 04:43:10