我尝试了以下方法,但未能匹配Json中的对象
:\s*(\{[^\"]*\})
我想知道如何将Json中的对象类型替换为对象列表。你知道吗
以下是Json的示例:
{
"resourceType": "ChargeItem",
"id": "example",
"text": {
"status": "generated",
"session": "Done"
},
"identifier": [
{
"system": "http://myHospital.org/ChargeItems",
"value": "654321"
}
],
"definitionUri": [
"http://www.kbv.de/tools/ebm/html/01520_2904360860826220813632.html"
],
"status": "billable",
"code": {
"coding": [
{
"code": "01510",
"display": "Zusatzpauschale für Beobachtung nach diagnostischer Koronarangiografie"
}
]
}
}
我需要转换成以下形式:
{
"resourceType": "ChargeItem",
"id": "example",
"text": [{
"status": "generated",
"session": "Done"
}],
"identifier": [
{
"system": "http://myHospital.org/ChargeItems",
"value": "654321"
}
],
"definitionUri": [
"http://www.kbv.de/tools/ebm/html/01520_2904360860826220813632.html"
],
"status": "billable",
"code": [{
"coding": [
{
"code": "01510",
"display": "Zusatzpauschale für Beobachtung nach diagnostischer Koronarangiografie"
}
]
}]
}
使用多行regexp搜索的解决方案
这似乎是一些简单的转换:
首先,改变
至
第二,改变
至
第三,改变
至
最后,改变
至
但是,它可能不像看上去那么简单,即如果
identifer
部分并不总是存在,或者没有立即跟随text
部分,该怎么办?你知道吗正则表达式是做这项工作的一个糟糕的选择。最好将json文件读入本地Python数据结构,应用所需的更改,然后将json保存回该文件。你知道吗
相关问题 更多 >
编程相关推荐