我有一些对象数组如下:
Object[] userObj = new Object[] {"userName: "+user,
"userId: "+id, "userCategory: "+category};
我想从我的对象中获取以下JSON:
{
"fault": {
"userName": "Test User",
"userObj": [{
"userId": "1"
}, {
"userCategory": "general"
}]
}
}
但我得到的是以下内容:
{
"fault": {
"userName: Test User",
"userObj": [{
"userId: 1"
}, {
"userCategory: general"
}]
}
}
有没有简单的方法在JSON中用冒号分隔的键值之间放置双引号?
答案 0 :(得分:0)
这应该有效
Object[] userObj = new Object[2];
userObj[0] = Collections.singletonMap("userName", user);
userObj[1] = Collections.singletonMap("userCategory", category);