0

I am new at iPhone Development.

I know how to store JSON data in database. But in my case I have .txt file which contain data of JSON. This .txt file i get by send request on Server and i got it as .zip file and after i did it as unzip file so after i get it as .txt file with JSON data. I get this data from .txt file but i dont know how to store it in database.I want to stor this data in DATABASE. How cant i do anybody as idea ???

Data of .txt file of JSON (Display in Console)

"Ok","last_response_date":"2013-02-05 00:04:14","region_master":[{"id":"1","region_name":"Auckland and Kermadec","border_coordinate_file":"","created_date":"2013-02-01 05:22:42","updated_date":"0000-00-00 00:00:00"},{"id":"2","region_name":"Central","border_coordinate_file":"","created_date":"2013-02-01 05:22:42","updated_date":"0000-00-00 00:00:00"},{"id":"3","region_name":"Challenger","border_coordinate_file":"","created_date":"2013-02-01 05:22:57","updated_date":"0000-00-00 00:00:00"},{"id":"4","region_name":"Fiordland","border_coordinate_file":"","created_date":"2013-02-01 05:22:57","updated_date":"0000-00-00 00:00:00"},{"id":"5","region_name":"South East","border_coordinate_file":"","created_date":"2013-02-01 05:23:15","updated_date":"0000-00-00 00:00:00"},{"id":"6","region_name":"Southland","border_coordinate_file":"","created_date":"2013-02-01 05:23:15","updated_date":"0000-00-00 00:00:00"}],
"region_kml_files":
[{"id":"4","region_id":"2","kml_files":"Sample.kml","created_date":"2013-01-25 09:04:58","updated_date":"0000-00-00 00:00:00"}]

EDIT :


I already got data from .txt file


please help me..
Thanks :)

4

2 回答 2

0

You can use:

 NSString *jsonString  = [NSString stringWithContentsOfFile:yourFilePath encoding:UTF8StringEncoding error:nil];

Here:

yourFilePath is a NSString which contains the exact path to the .txt file.

You get the file content in jsonString variable, you need to save that string to database.

Refer NSString class for more

于 2013-02-05T05:33:13.063 回答
0

I don't know where you are having trouble, but it seems like you haven't gotten a JSON object from your string yet, so I will let you know how to do that. If you need to know how to create and store data in a database, then you need to make a new question and say that you got JSON data but are having trouble storing it into a database (at least make an effort to try to do it though).

You can use NSJSONSerialization to get an object out of your string (the NSData version of your string, at least). It will look like this:

NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:yourData options:kNilOptions error:nil]; 

If it doesn't work then your JSON is not valid. Validate it at http://www.jsonlint.com

于 2013-02-05T06:04:46.153 回答