Reputation: 742
I load json-data from my server by using FMDB. The response I get (JSON), I'm storing in a sqlite-database (same string as the response below gets stored in the database). Later on I select that data from the database through FMDB and trying to build up a NSDictionary from it, but can't get it to work.
The json-response I get from the server looks like below (shortened down the response for this post, so it contains some more...) when I output it through NSLog:
{
response = {
data = {
"dbId_1" = {
1 = {
current = {
weekday = Tuesday;
};
};
};
};
};
}
This is how I select it from the database and what I want to make a NSDictionary from:
NSString *jsonString = [results stringForColumn:@"json"];
Is it possible to build up everything again to a NSDictionary?
Upvotes: 4
Views: 1598
Reputation: 11607
Add JSONKit to your project, #import "JSONKit.h" then go:
NSDictionary *jsonDict = [yourJSONStringFromDB objectFromJSONString];
If you're using Automatic Reference Counting, then you'll need to open up your Project Settings > Build Phases > Compiled Sources Panel
Look for "JSONKit.m" line and double click on it, add "-fno-objc-arc" to force no automatic reference counting for this file.
JSONKit can be downloaded here: https://github.com/johnezang/JSONKit
Upvotes: 1
Reputation: 1070
In my opinion, you will need to build the entire dictionary.
From the data that you have stored in the SQLite database, you will have to save the "key" and "value" pair into the dictionary.
I used a similar coding structure sometime back, and I used an array for it.
I hope this helps.
Upvotes: 0