一,代码。
- (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" }
{"name":"李华", "sex":"女", "age":"20" }"];
NSLog(@"-----jsonStringOther---%@",jsonStringOther);
NSArray *jsonArray = [jsonStringOther componentsSeparatedByString:@"
"];
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":"U674eU534e", "sex":"U5973", "age":"20" }",
"{"name":"U674eU534e", "sex":"U5973", "age":"20" }"
)