【发布时间】:2016-07-27 19:25:22
【问题描述】:
我需要在 JSON 中返回一个字符串来组合 json 对象和 json 数组 这是我需要的例子
{
"scode" : "62573000", "sname" : "Burn of right",
"icd10" = [
{"icode" : "T25.229?", "iname" : "Right foot"}
{"icode" : "T25.22941?", "iname" : "left foot"}
],
"refinement" = [
{"rname" : "Refinement1"},
{"rname" : "Refinement2"}
]
}
但我越来越喜欢了
{
"icdcode": "T25.229?",
"snomedcode": "62537000",
"snomedname": "Second degree burn of foot (disorder)",
"icdname": "Burn of second degree of unspecified foot, episode of care unspecified"
}
这是代码
oJsonAry = new JSONArray();
while (resultSet.next())
{
JSONObject oJsonOther = new JSONObject();
JSONObject oJsonRefine = new JSONObject();
hMapotherwise = new HashMap<String, String>();
maprule = (resultSet.getString("mapRule"));
if (maprule.matches("OTHERWISE TRUE")|| maprule.matches("TRUE"))
{
strSnomedCode=resultSet.getString("referencedComponentId");
hMapotherwise.put("snomedcode", strSnomedCode);
strSnomedDesc=resultSet.getString("sctName");
hMapotherwise.put("snomedname", strSnomedDesc);
strIcdCode=resultSet.getString("mapTarget");
hMapotherwise.put("icdcode", strIcdCode);
strIcdName=resultSet.getString("icdName");
hMapotherwise.put("icdname", strIcdName);
oJsonOther.putAll(hMapotherwise);
oJsonAry.add(oJsonOther);
}
refid = resultSet.getInt("refid");
pipe = resultSet.getString("mapRule").split("\\|");
if (pipe.length > 1)
{
bSubmit = true;
oJsonRefine.put("maprule", pipe);
oJsonAry.add(oJsonRefine);
}
if(oJsonAry != null)
{
strJSON = oJsonAry.toJSONString();
}
}
}
我需要在我的 java 代码中更改哪些内容,并且我对此很陌生,所以我会陷入困境。有人能说如何克服这个问题吗。最后我必须返回 strJSON
【问题讨论】:
-
请包含一个实际的minimal reproducible example。
标签: java arrays json object jsonobject