哥 你解决了吗
云开发,数据库返回的JSON数据如何再插入数据库?通过 WEB API 请求返回的数据,data里的数据有 \ " 等等,这个格式怎么插入数据库呢? 想要通过这个接口,把下面data里的数据插入数据库:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html // 这个是查询数据库返回的数据 { "errcode": 0, "errmsg": "ok", "data": [ "{\"_id\":{\"sid\":{\"$numberDouble\":\"1003.0\"},\"mobile\":\"00000000000\"},\"totalCount\":{\"$numberInt\":\"12\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1003.0\"},\"mobile\":\"11111111111\"},\"totalCount\":{\"$numberInt\":\"62\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1003.0\"},\"mobile\":\"22222222222\"},\"totalCount\":{\"$numberInt\":\"63\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1004.0\"},\"mobile\":\"33333333333\"},\"totalCount\":{\"$numberInt\":\"34\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1005.0\"},\"mobile\":\"44444444444\"},\"totalCount\":{\"$numberInt\":\"84\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1007.0\"},\"mobile\":\"55555555555\"},\"totalCount\":{\"$numberInt\":\"28\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}", "{\"_id\":{\"sid\":{\"$numberDouble\":\"1006.0\"},\"mobile\":\"66666666666\"},\"totalCount\":{\"$numberInt\":\"30\"},\"created\":\"{\\\"$date\\\":{\\\"offset\\\":0}}\",\"createdMS\":{\"$numberLong\":\"1630921631001\"},\"createdStr\":\"2021-09-06 17:47:11\",\"createdDayStr\":\"2021-09-06\"}" ] } // 我想通过这段代码把上面的data里的数据加到数据库里 JSONArray data = res.getJSONArray("data"); // 发送请求 http api String querystr = "db.collection('ordercollect').add({\n" + " data: " + data + "\n" + "})"; JSONObject body = new JSONObject(); body.put("env", env); body.put("query", querystr); 文档里的data格式: [图片]
2021-11-10