【发布时间】:2013-12-20 17:10:16
【问题描述】:
我有一个配置文件,其内容是这样的:
main = {
delay = 10000;
inputs = (
{
enabled = true;
ip = "127.0.0.1";
port = 10001;
file = "c:\abc.txt";
},
{
enabled = true;
ip = "127.0.0.1";
port = 10002;
file = "c:\myfile.txt";
},
);
}
现在,我想解析这个文件,例如,获取第二个输入的端口号(即本例中的 10002)等。
你知道在目标 C 中最简单的方法是什么吗?
谢谢!
【问题讨论】:
-
转换 JSON -> JSONKit 或 NSJSONSerialization
-
这看起来像
NSDictionary的 NSLog 输出(或description),它不适合作为配置文件格式,因为它不能可靠地解析回来(比较 stackoverflow.com/questions/16783635/… 的类似问题)。 - 如果可能,选择不同的配置文件格式(例如 JSON)。
标签: objective-c parsing