解析逗号分隔列表的最佳方法 [英] Best way to parse comma seperated list

查看:184
本文介绍了解析逗号分隔列表的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆