Convert JSON to .plist - ios

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
I have a JSON file that I exported from a web service. I need to convert this to a .plist file that I can import into the main bundle of an iOS app. What's the easiest way to do this?
Note - the app doesn't need to grab the JSON from a server or anything. This is a one-time conversion that I need to do. The app will always just use the plist. I just need to know how to convert it.

I'd recommend plutil on the command line.
plutil -convert xml1 in.json -o out.plist
It will blow up with NULL values in dictionaries and some other inconsistencies that iOS JSON deserialization will handle more gracefully, but it does appear to work pretty well.

I wrote an online converter to do this. Please have a try.
http://json2plist.sinaapp.com/

David's answer works pretty well, but as a Ruby lover I've written a very simple tool to do the same with ruby: https://github.com/javiertoledo/json2plist

another online converter JSON to PList
https://wtools.io/convert-json-to-plist

Related

Swift - how do i convert a regular XML file to a .plist XML file

I searched the web for this one and mostly found Obj-C answers or outdated answers so ill simply post the question and hope for the best :)
Im working with a team of Android Developers while im working on IOS. they use XML files for a lot of data. since we want the data between us to stay consistent - we want to be able to have shared XML files to use in our projects.
I know .plist is basically a type of XML, but i want to be able to get the regular shared XML file and turn it into a .plist and then use it in my IOS project.
any known method of doing it at all? if so, is it possible to do it automatically somehow? (script or something of that sort. maybe even do it locally inside the application)
Thanks for the help
A .plist file is a very specific XML file with only a small set of keys allowed. A random XML file will not be convertible to a .plist file.
Try converting your file to JSON first. If you can convert it to JSON you will be able to automatically convert it to a .plist after that using the plutil command with the xml1 or binary1 format.
plutil -convert xml1 -o output.plist input.json
If you can't convert it to JSON, you can keep your XML file as is and parse it in your app using NSXMLParser. XML is harder to parse than .plist or JSON files, but aside from that the difference should be minimal.

How to implement a swift code to generate xml file

well i've tried to do some code that can do a xml file in a "well done" way, I found this code https://gist.github.com/brentdax/caaaa134c500e00efd36
and i think is a good option to implement that i wish. but i can implementa that.
actually i implements but the error says: use of undeclared type NSXMLNode.
I tried to put it on source file, in a playgrouns on viewcontroller code file without success
I don`t know how can implement this.+
thanks in advice
If you want help fixing your code you need to show us that code.
Failing that, take a look at the NSXMLParser class. It's fairly easy to use.
EDIT:
This is a very old thread, but rmaddy pointed out that the question was about generating XML, and my solution of using NSXMLParser will parse XML, but not generate it.
I recently found a reference to the XMLParsing library, which apparently follows the conventions of the Codable protocol. I suggest using that.

Is there any documentation about MSKLC .klc file format?

I need to parse .klc files from msklc and I can't find any docs about it's format.
I know this format is simple, but I have some misunderstanding. So where I can find information about it?
I have found some code in the keyboard layout tool, which might help you. I have pasted it Here. I extracteded it from the exe using il-spy.
Apparently the code parses the klc file for you.
I have not tested it out, but it could serve as a starting point.

How can we write Structures in file?

I am new to IOS programming. I want to write a C style structure into file and retrieve back.
I am able to write string into file after getting Document directory path. But how to write a structure in that file. Can anyone help?
You'd likely be most interested in the NSCoding protocol, as well as the Creating and Extracting Archives and Encoding and Decoding Objects in the Archives and Serialization guide.
Normal C way of I\O operation worked well, however the to write file in particular location we need permission.

Parse Lego Digital Designer *.lxf files

I was toying with Lego digital designer the other day (http://ldd.lego.com/) and I was wondering if the saved file could be relatively easily parsed.
As anybody ever done that before? I'm looking for code examples, no matter the language :)
Thanks !
Romain
Maybe this would help: http://bricksviewer.sourceforge.net/index.shtml
A .lxf file is just a zip file, on the page I mentioned there is a short description of the format. For more details you should read the source.

Resources