【发布时间】:2011-12-10 20:41:04
【问题描述】:
我正在尝试将 JSON 字符串附加到已经包含更多 JSON 字符串的文件中:
[
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnMiP"
},
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnZiP"
},
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnAiP"
}
]
我需要附加 {"title":"test","content":"test","date":"2011-12-10 21:35:48 +0100","author":"zad0xsis","id":"0EhQ0"} 之类的字符串,以保留 JSON 格式:
[
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnMiP"
},
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnZiP"
},
{
"title": "A test title",
"content": "A test content",
"date": "10/01/10",
"author": "zad0xsis",
"id": "vnAiP"
},
{"title":"test","content":"test","date":"2011-12-10 21:35:48 +0100","author":"zad0xsis","id":"0EhQ0"}
]
所以它看起来像这样,简而言之,附加它使其仍然是有效的 JSON。如何在 Ruby 中实现这一点?谢谢!
【问题讨论】:
标签: ruby json formatting append