FMDB, sqlite json-string to dictionary?

I am downloading json data from my server using FMDB. The answer that I get (JSON), I store in the sqlite database (the same line as the answer below is stored in the database). Later, I select this data from the database via FMDB and try to create an NSDictionary from it, but I can not get it to work.

The json-response I get from the server looks lower (shortened the response to this post, so it contains a few more ...) when I output it via NSLog:

{ response = { data = { "dbId_1" = { 1 = { current = { weekday = Tuesday; }; }; }; }; }; } 

This is how I select it from the database and what I want to make NSDictionary from:

 NSString *jsonString = [results stringForColumn:@"json"]; 

Can everything be created again in NSDictionary?

+4
source share
2 answers

Add JSONKit to your project, #import "JSONKit.h", then go:

 NSDictionary *jsonDict = [yourJSONStringFromDB objectFromJSONString]; 

If you use automatic link counting, you need to open your settings Project> Build Phases> Panel of Compiled Sources

Look for the line "JSONKit.m" and double-click on it, add "-fno-objc-arc" so that there is no automatic reference counting for this file.

JSONKit can be downloaded here: https://github.com/johnezang/JSONKit

+1
source

In my opinion, you will need to build the entire dictionary.

From the data that you saved in the SQLite database, you will need to save a pair of "key" and "value" in the dictionary.

I used a similar coding structure sometime ago, and I used an array for it.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1436162/


All Articles