Here is the situation..
I've inserted a whole NSArray
in one field of my SQLite
table, now I retrieve the data and it becomes a string. How can I convert it into NSArray
again?
This is the contents of my NSArray
inserted in SQLite
:
"<tbl_news:annyfksM8D:(null)> {\n \"news_content\" = \"Lorem ipsum dolor sit\";\n \"news_date\" = \"Sep 23, 2013\";\n \"news_featuredimage\" = \"uploads/1373124691956-160x120.jpg\";\n \"news_title\" = \"Lorem Ipsum2\";\n}",
"<tbl_news:fEgOpdgflF:(null)> {\n \"news_content\" = \"Lorem ipsum dolor sit.\";\n \"news_date\" = \"Sep 23, 2013\";\n \"news_featuredimage\" = \"uploads/2560x1440.jpg\";\n \"news_title\" = \"Lorem Ipsum3\";\n}"
It is an array from parse. Can anyone know how will i be able to convert it to NSArray
. I've already tried Convert NSString to NSArray but i think doing the solution there will no solve my problem.
Don't store your NSArray as a string into your database. Convert it to NSData, store it as a blob, retrieve it back as NSData, and then convert that back into an NSArray:
// Convert NSArray to NSData
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
...
// Store it as a blob in sqlite
sqlite3_bind_blob(insert_statement, 1, [data bytes], [data length], NULL);
...
// Get the bytes back fromthe database and convert it into an NSArray
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.