我有一個字符串,它是從json格式的web服務器獲得的,但字符串對於其中的所有內容都很大。我嘗試使用NSDICTIONARY,但沒有成功。我想知道什麼是最好的方法來打破這個字符串,並添加到不同的字符串,並最終把它們放在一個字符串類。謝謝您的幫助!這裏是我的代碼:來自Json的Break字符串
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:@"http://mym2webdesign.com/meiplay/paulsuckedabuffalo/artists.php"]];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; //Or async request
returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSError *error=nil;
NSLog(@"HHHHHHHHHHHHHH"); //use this to know how far Im getting
NSLog(returnString); // Look at the console and you can see what the restults are
/*NSDictionary *results = [returnString JSONValue];
NSString *ID = [results objectForKey:@"ID"]; // for example
NSLog(@"ID Number: %@", ID);*/
下面是一些日誌我得到的:
[{"ID":"1","name":"kevin","bio":"kevins bio"},{"ID":"1","name":"kevin","age":"20"},{"ID":"2","name":"Cesar","bio":"Cesar bio"},{"ID":"2","name":"Cesar","age":"19"},{"ID":"3", "name":"Katherine", "bio":"Katherines bio"},{"ID":"3", "name":"Katherine", "age":"22"}]
最外層是一個數組。這可以通過封閉的[]'字符容易地看到。 JSON的語法非常簡單,您需要了解它 - 請參閱http://www.json.org/ - 它將花費所有10分鐘的時間來學習,然後您不必乞求其他人爲你寫代碼。 – 2013-05-01 03:25:06
謝謝,這將幫助很多! – paul590 2013-05-02 00:38:51