我有一个json,看起来像这样:
{
"course1": [
{
"courseName": "test",
"section": "123",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "456",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "789",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "1011",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1213",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1415",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
]
}
我想组合任何块/对象/列表(我不知道它叫什么),它们有相同的键值。 像这样:
{
"course1": [
{
"courseName": "test",
"section": "123",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course2": [
{
"courseName": "test",
"section": "456",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "789",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "1011",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
],
"course3": [
{
"courseName": "test",
"section": "1213",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
},
{
"courseName": "test",
"section": "1415",
"academicHours": "3",
"day1": "1",
"room1": "0145 03 1 B 015"
}
]
}
如何在python中使用正则表达式实现这一点?或者任何正则表达式查询?你知道吗
另外,我试着使用json.dumps()
并从那里开始工作,但由于某种原因,当我将它与任何包含阿拉伯语字符的json一起使用时,它会发疯并把整个事情搞砸。
很不幸,我被正则表达式困住了。你知道吗
谢谢你的帮助:)
stdlib
json
提供了一个钩子,允许对具有重复键的对象进行解码。这个简单的“扩展”钩子应该适用于您的示例数据:尽管the JSON specification中没有禁止重复键的内容,但首先应该避免:
。。。你知道吗
相关问题 更多 >
编程相关推荐