从文件读取JSON,用选定值格式化输出
假设我在从文件读取JSON,用选定值格式化输出,json,format,Json,Format,假设我在calendar.json文件中有以下内容: { "dates":[{ "id": "1", "month_name": "january", "day_name": "wednesday", "day": "1", "month": "1", "holiday": "Some Holiday Label", }, { "id": "2"
calendar.json
文件中有以下内容:
{
"dates":[{
"id": "1",
"month_name": "january",
"day_name": "wednesday",
"day": "1",
"month": "1",
"holiday": "Some Holiday Label",
},
{
"id": "2",
"month_name": "january",
"day_name": "thursday",
"day": "2",
"month": "1",
"holiday": "Some Other Holiday Label",
}
]}
我希望在另一个文件中获得如下格式的结果:
holiday.sr-RS1.name=Some Holiday Label # here would be the data extracted from holiday field of the above `json`
holiday.sr-RS1.date=20140908 # here would be the data extracted from day,month field
# ,and manually added year to form date in that specific format
像这样格式化输出当然不是问题,我的问题是什么
如果我要用最简单的方法来完成这项工作,我尝试使用python,但没有成功
一些奇怪的问题无法读取json
文件,因为
意外的UTF-8 BOM
错误。我不喜欢任何特定的编程
语言,我只是对解析这个JSON并输出它的最佳方式感兴趣
以我需要的格式写入文件。看看这里,如何避免Python中的BOM错误:这很有帮助。谢谢。