gpt4 book ai didi

java - 如何将字符串值作为json对象存储在mongodb中?

转载 作者:行者123 更新时间:2023-11-30 04:36:02 26 4
gpt4 key购买 nike

我从 UI 获取数据如下,以下所有输入数据都是字符串。

cust_id:temp001cust_chart_id :测试默认图表:假Chart_pref_json :{范围:6m,chart_type:烛台,指标:{},周期:每日,futurepadding:20} }

我正在尝试将chart_pref_json存储在mongodb中。这个chart_pref_json对象实际上是作为下面的字符串存储在db中的,

{ "_id" : ObjectId("50aca4caf5d0b0e4d31ef239"), "cust_id" : "temp001", "cust_chart_id" : "testing", "default_chart" : "false", "created_at" : NumberLong("1353491658551"), **"chart_pref_json" : "{range:6m,chart_type:candlestick,indicators:{},period:Daily,futurepadding:20}" }**

但我实际上希望将此 Chart_pref_json 存储为 json 对象,如下所示。

{ "_id" : ObjectId("50aca4caf5d0b0e4d31ef239"), "cust_id" : "temp001", "cust_chart_id" : "testing", "default_chart" : "false", "created_at" : NumberLong("1353491658551"), **"chart_pref_json" : {range:6m,chart_type:candlestick,indicators:{},period:Daily,futurepadding:20} }**

谁能帮我解决这个问题。

最佳答案

当您将 JSON 代码作为字符串时,您首先必须解析 JSON 代码,然后将生成的 JSON 对象转换为 BSON 对象。

您可以使用类 com.mongodb.util.JSON MongoDB 附带的。 Here is a tutorial .

关于java - 如何将字符串值作为json对象存储在mongodb中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com