[英]Convert json files to plist in mac
Is there a command line tool that will let me do that? 有命令行工具可以让我做到吗? I have tried plutil but that doesn't work.
我已经尝试过plutil,但这不起作用。 I think plutil can only convert files from plist (or binary plist) format.
我认为plutil只能从plist(或二进制plist)格式转换文件。
If you are happy with a very-tiny Cocoa App for this, then this can be generated, a lot of code are available. 如果您对一个非常微小的Cocoa App感到满意,那么可以生成此代码,可以使用很多代码。
Or, 要么,
You can use this python script : 您可以使用以下python 脚本 :
#!/usr/bin/env python
import plistlib
import json
import tkFileDialog
import re
import sys
file_to_open = tkFileDialog.askopenfilename(message="Select an existing plist or json file to convert.")
converted = None
if file_to_open.endswith('json'):
converted = "plist"
converted_dict = json.load(open(file_to_open))
file_to_write = tkFileDialog.asksaveasfilename(message="Select a filename to save the converted file.",
defaultextension = converted)
plistlib.writePlist(converted_dict, file_to_write)
elif file_to_open.endswith('plist'):
converted = "json"
converted_dict = plistlib.readPlist(file_to_open)
converted_string = json.dumps(converted_dict, sort_keys=True, indent=4)
file_to_write = tkFileDialog.asksaveasfilename(message="Select a filename to save the converted file.",
defaultextension = converted)
open(file_to_write, 'w').write(converted_string)
else:
print("WHAT THE F*** ARE YOU TRYING TO DO??????")
sys.exit(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.