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 :)
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
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
Related
I want to use a JSON file as temp data saving and edit it.
this is how I get data from local, I want to get file from internet and edit it.
var mydata = json.decode(await rootBundle.loadString('/assets/testjson.json'));
thanks in advance.
I am trying to create an app where users can upload files to the "wall". The idea is not important. Each file is added both to storage and to database as [fileName : url) under user's profile. Because of limitations regarding strings in database, I keep filenames without extensions (can't use dot symbol). Uploading works fine but I have a problem with deletion. Based on the file user picks to delete in app I get the filename(without extension). My delete function should delete the file from storage but it cannot locate file because of missing extension.
I use this function to upload the data:
let uploadTask = ref.putData(contents as Data, metadata: myMetadata, completion: { (metadata, error) in ...}
and the file itself:
let contents = try Data(contentsOf: url.standardizedFileURL)
Is it possible to upload "contents" without the extension? Or maybe is there another approach I'm missing?
Thanks for tips.
It's not a really good idea to store the names of random things (including files) as keys in Realtime Database. You could make this easier on yourself by pushing an object at a location in the database for each file uploaded. The pushed object could contain the name and location of the file in Storage, along with any other metadata about that file, and you won't have to mangle that data as long as it's stored in values rather than keys.
I got a JSON response with a lot of data.
(e.g.: Private Messages).
How to display them into a table?
I mean in C#.net I normaly would have a class (PM) with a lot of Properties (sender, reciever, subject, text) and make a database-query (here JSON) and fill it in a list of my class (List pmList = new pmLIst();).
How to do it in Objective C for iPhone?
Have a look at SBJson. The TweetStream example project shows how to fetch data over an HTTP connection and parse it. If the data contains a list of objects you'll find those in an NSArray in your parsed data; at that point it's simply a matter of using a UITableView to display the data.
Have a look at restkit. It's a nice framework for parsing JSON and putting it into the right structure. The examples provided there should get you started.
My xml is
<categoryname>Baby</categoryname>
<id>244</id>
<categoryname>Boats & Watercraft</categoryname>
<idc>1026</id>
I am getting first two nodes.My problem is the third node i am getting Boats only (parser foundCharacters) and & kills the nsxmlparser. I am searching this forum and other websites most of them post use & instead of & in xml . My xml is coming from server and i wont update xml now.Is there any other option to solve this issue.
If you insist on sending invalid XML from your server this should solve it:
[xmlString stringByReplacingOccurrencesOfString:#"&" withString:#"&"]:
// parse xmlString
[categoryName stringByReplacingOccurrencesOfString:#"&" withString:#"&"]:
If your xml might be coming from some php script then before sending it you have to make change in your script that when & character occurs it substitute with other character like $ or any other and then send it. And when you parse that xml change that symbol to your required symbol.
I have also done the same thing.
i am working with web services these days ,and with all xml files that i am parsing things are fine ,but with the last one the famous method "stringWithContentsOfURL" returns empty data. Why?
Most likely your URL references a non-existing file, or the content of the file can not be encoded as a NSString.