我尝试在Android中的Couchbase文档中保存属性。 这些属性包含一个带有多个JSONObject的JSONArray。
当document.putproperties(myproperties)
couchbaseliteexception
{strong}状态400 和消息" bad or missing json" is thrown
"时
所以JSONArray看起来像:
"some_prop" -> "[
{
"content":"someContent",
"key2":"",
"key3":"",
"key4":"",
"month":8,
"day":3,
"key5":115
},
{
"content":"Some other content",
"key2":"something",
"key3":"",
"key4":"",
"month":8,
"day":3,
"key5":115
}]"
有谁能告诉我这个JSON的问题是什么?
编辑: 具有相应键的JSONArray保存在散列映射中,如下所述: http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/document/index.html
编辑2: 执行更新并填充JSONArray的方法:
private void updateDoc(ArrayList<MyObject> objects) {
Document document = getDocument();
// Update the document with more data
Map<String, Object> updatedProperties = new HashMap<>();
JSONArray objectArray = new JSONArray();
//fill array with data
for(MyObject element : objects) {
JSONObject jsonObjects = element.toJSONObject();
if(jsonObjects != null) {
objectArray.put(jsonObjects);
}
}
//set data to property map
updatedProperties.put(MYOBJECT_PROP_IDENTIFIER, objectArray);
try {
// Save properties to the Couchbase local Couchbase Lite DB
document.putProperties(updatedProperties);
} catch (CouchbaseLiteException e) {
}
}
答案 0 :(得分:0)
不确定这是否是您正在寻找的,
您还可以使用类似http://jsonlint.com的内容来验证您的儿子
{
"some_prop": [
{
"content": "someContent",
"key2": "",
"key3": "",
"key4": "",
"month": 8,
"day": 3,
"key5": 115
},
{
"content": "Some other content",
"key2": "something",
"key3": "",
"key4": "",
"month": 8,
"day": 3,
"key5": 115
}
]
}