一,代碼。 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"字元串的分割"; //一般的字元串的解析 NSString *string ...
一,代碼。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title=@"字元串的分割";
//一般的字元串的解析
NSString *string = @"One,Two,Three,Four";
NSLog(@"string:%@",string);
NSArray *array = [string componentsSeparatedByString:@","];
NSLog(@"array:%@",array);
//兩個json數組連在一起的解析
NSString *jsonStringOther=[NSString stringWithFormat:@"{\"name\":\"李華\", \"sex\":\"女\", \"age\":\"20\" }\n{\"name\":\"李華\", \"sex\":\"女\", \"age\":\"20\" }"];
NSLog(@"-----jsonStringOther---%@",jsonStringOther);
NSArray *jsonArray = [jsonStringOther componentsSeparatedByString:@"\n"];
NSLog(@"jsonArray:%@",jsonArray);
}
二,輸出。
2015-10-22 11:13:21.872 字元串的分割[4057:112931] string:One,Two,Three,Four
2015-10-22 11:13:21.873 字元串的分割[4057:112931] array:(
One,
Two,
Three,
Four
)
2015-10-22 11:13:21.873 字元串的分割[4057:112931] -----jsonStringOther---{"name":"李華", "sex":"女", "age":"20" }
{"name":"李華", "sex":"女", "age":"20" }
2015-10-22 11:13:21.873 字元串的分割[4057:112931] jsonArray:(
"{\"name\":\"\U674e\U534e\", \"sex\":\"\U5973\", \"age\":\"20\" }",
"{\"name\":\"\U674e\U534e\", \"sex\":\"\U5973\", \"age\":\"20\" }"
)