【发布时间】:2016-02-15 09:41:59
【问题描述】:
我正在开发一个用户向服务器发送文本的应用程序。然后服务器更改文本,并以原始文本和修改后的文本进行响应。
如何表示在 JSON 中删除的文本。 (删除线)
比如这样:
我想过这样的事情:
包含所有文本的数组,拆分到包含笔划的位置,以及不包含笔划的位置:
data={
textBefore:'this is the first world. this is the second world',
textAfter:'this is first world. this is second world,
changes:[
{'nostroke':'this is th'},
{'stroe':'efirst world'},
{'nostroke':'in the third world'}
]
}
你有更好的主意吗?
或者像这样:
data={
textBefore:'this is the first world. this is the second world',
textAfter:'this is first world. this is second world,
changes:[
{from:2,to:22,text:'repace from char 2 to char 22 with this text'},
{from:2,to:4} // This will only delete 2 chars
{from:2,to:2,text:'This will only append this text without replae},
]
【问题讨论】:
-
JSON 支持字符串、对象、数组、布尔值和其他几种数据类型。它没有内置任何内容来描述这一点,所以答案是“随你喜欢”,这是意见的问题。
-
我可以问如何在表格中表示某些东西,如何在 UML 图中表示某些东西。所以我在问如何将现实世界的数据转换为 JSON 格式。
-
是
Then the server <s>change</s> the text真实世界数据 ? -
你的问题可能是个好问题,但你必须发展。添加一些约束和描述。
标签: javascript json strikethrough