10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSONをplistに変換したい

Posted at

JSONで用意されているデータをNSArrayNSDictionaryにして使いたかった。

結論

これでいい

$ plutil -convert xml1 hoge.json -o hoge.plist

解説

plutilはplistがらみのユーティリティで、一コマンドにいろんな機能がまとまった良くない設計の見本みたいな便利ツールです。

plutilが変換できるフォーマットは以下の3種類。

  • json
  • xml1
  • binary1

plistにはXML形式とバイナリ形式があることをご存知なら、特に説明はいらないと思います。

-convertの引数には出力フォーマット名を書きます。
入力のフォーマットは自動で認識してくれるみたいです。
json -> xml1 だけでなく、 xml1 -> json もできます。

ちなみに-oオプションを忘れると 入力ファイルを上書きされる ので注意しましょう。
(stdoutに出てくるものだと思ってはいけない。-o -とすればstdoutに出てくる)

あとは

適当にNSBundleとかでファイルパスを取ってきてNSArray#arrayWithContentsOfFileとかで使えるようにしたら幸せになれた。

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?