我有一个JSON对象,在resource_hours
字段中我想存储一个JSON字符串
{
"id": 4,
"resource": 1,
"resource_hours": "json goes here",
"start": "2009-10-10",
"end": "2010-10-10",
"created_at": "2017-06-01T13:23:06.103867Z",
"modified_at": "2017-06-01T13:23:06.103867Z"
}
下面是我要存储的字符串/对象:
{
"winner": "john",
"loser": "not john"
}
我试过这个:
"resource_hours": "{"winner":"john","loser":"not john"}"
但很明显,由于双引号重叠,这就产生了一个错误
我还尝试使用\
来转义引号,如下所示:
"resource_hours": "{\"winner\":\"john\",\"loser\":\"not john\"}"
这是有效的(没有引发错误),但它仍然是一个JSON字符串/对象吗?如果使用API从数据库中提取,它仍然可以被解析为JSON对象吗
JSON.stringify
方法允许您将对象转换为字符串:现在,
object.resource_hours
有一个字符串,在解析时引用objectWillBeStoredInJson
您可以使用
JSON.parse
来访问它:这将适用于使用Python的用户:
快乐编码
相关问题 更多 >
编程相关推荐