org.json的嵌套数组

时间:2018-07-14 13:36:00

标签: java arrays json

我尝试使用jsonobject和jsonarray为以下json blob构建嵌套数组。由于某种原因,对象出现故障。任何想法-请,我们如何最好地采用这种格式。

{
  "reporter_desc": "pot",
  "timestamp": "1487830751",
  "incidents": [
    {
      "src_ip": 822382162,
      "exploit": "scan",
      "incident_type": 3,
      "occurred": "1487830751",
      "description": "pot scan"
    }

这是JSONObject和JSONArray:

JSONObject object = new JSONObject();
object.put("reporter_desc", "mtpot");
object.put("timestamp", "1487830751");
JSONArray array = new JSONArray();

JSONObject arrayElement = new JSONObject();
arrayElement.put("src_ip", 822382162);
arrayElement.put("exploit", "scan");
arrayElement.put("incident_type", 3);
arrayElement.put("occurred", "1487830751");
arrayElement.put("description", "pot vulnerability scan");
array.put("incidents");
object.put("incidents", array);

0 个答案:

没有答案