解析逗号分隔列表的最佳方法 [英] Best way to parse comma seperated list
问题描述
我reciving从我与通信服务器的JSON数据包,我回来了请求中的一个具有JSON数组中的一个项目是returnes这是逗号分隔字符串的字符串。
它看起来像这样,当我的NSLog的JSON数据包作为一个数组。
(
\\完成\\,\\半拉子值\\,\\损坏值\\,
,
0
)
我可以访问JSON数组像这样的第一项
的NSString * firstJSONString = [jsonArray objectAtIndex:0];
我就再像分析它,因为我要去值存储到coredata对象的最佳/最efficiant方式。
所以我的问题是我怎么能解析这个逗号分隔字符串?
任何帮助将是AP preciated三江源。
的NSArray *项目= [firstJSONString componentsSeparatedByString:@];
或
的NSArray *项目= [firstJSONString componentsSeparatedByString:@\\,\\];
然后删除 \\
从第一项和 \\
在最后一节
I am reciving a JSON packet from a server I am communicating with, one of the requests I get back has an item in the JSON array that returnes which is a string of comma seperated strings.
it looks like this when I NSLog the JSON packet as an array.
(
"\"Completed\",\"UnCompleted Value\",\"Damaged Value\"",
"",
0
)
I can access that first item of the JSON array like this
NSString *firstJSONString = [jsonArray objectAtIndex:0];
I would then like to parse it the best/most efficiant way as I am going to store the values into a coredata object.
So my question is how can I parse this comma seperated string? Any help would be appreciated thankyou.
NSArray *items = [firstJSONString componentsSeparatedByString:@","];
or
NSArray *items = [firstJSONString componentsSeparatedByString:@"\",\""];
And then delete \"
from the first item and \"
in the last one
这篇关于解析逗号分隔列表的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!