Objective c 在iphone上为sqlite将json转换为常量字符
我在存储下载的一些json数据时遇到问题。我认为问题在于从字符串到json再到常量字符的转换。也许还有更好的方法。这是我的Objective c 在iphone上为sqlite将json转换为常量字符,objective-c,ios,json,sqlite,nsdictionary,Objective C,Ios,Json,Sqlite,Nsdictionary,我在存储下载的一些json数据时遇到问题。我认为问题在于从字符串到json再到常量字符的转换。也许还有更好的方法。这是我的 NSDictionary *jsonAll = [[(NSString *)response uppercaseString] JSONValue]; //Get the objects within the seat number object NSDictionary *seatInfo = [jsonAll objectForKey:seatMessage];
NSDictionary *jsonAll = [[(NSString *)response uppercaseString] JSONValue];
//Get the objects within the seat number object
NSDictionary *seatInfo = [jsonAll objectForKey:seatMessage];
//Split the objects up accoridng to the track information -- we will have to structure
//we havethe maeesge with how ever many track
NSMutableString *Track1 = [seatInfo objectForKey:@"TRACK1'];
NSMutableString *Track2 = [seatInfo objectForKey:@"TRACK2"];
我带来的json文件如下所示
{A1 = {
TRACK1 = (
1462527,
1462527,
1462527,
1462527,
1462527,
1462527,
1462527,
1462527,
1462527,
1462527,
1462527
);
TRACK2 = (
12800016,
12800016,
12800016,
12800016,
12800016,
1462527,
12800016,
12800016,
12800016,
12800016,
12800016
);
};
}
我认为问题在于新线。当我尝试在sql中存储数据时,据我所知,我必须将其转换为常量字符
有人知道怎么做吗
谢谢
//获取seat number对象中的对象
NSDictionary *seatInfo = [jsonAll objectForKey:seatMessage];
//根据轨迹信息将对象拆分——我们将不得不构建//我们有梅斯基号,有多少轨道
NSArray *Track1 = [seatInfo objectForKey:@"TRACK1'];
for(id str in Track1)
{
//save the strings in database
}
您显然没有阅读上一个查询的注释--
[seatInfo objectForKey:@“TRACK1']
返回一个NSArray,而不是一个NSMutableString。NSArray的可能重复给了我同样的错误。我得到了正确的信息并将其拆分。但现在的问题是,我正试图将该字符串或数组更改为一个字符,以将其存储到sqlTry中。请阅读NSString的规范。并在web上搜索其他SQL的一些示例Objective-C.BTW中的ite操作:NSArray中的内容将是一组NSNumber对象,然后必须将其转换为整数。您必须决定如何将整数写入SQLite中--作为单个项,或字符串中的列表,或blob,或是什么?
NSArray *Track1 = [seatInfo objectForKey:@"TRACK1'];
for(id str in Track1)
{
//save the strings in database
}