将JsonArray转换为JsonObject Jquery

我想从此将JsonArray转换为JSON对象:

[{
  "departmentID":"baccf1ba-d9ca-4480-46cd-08d7e5f27472",
  "criteria":"absensi",
  "weight":21,
  "status":true
}]

对此:

{
  "departmentID":"baccf1ba-d9ca-4480-46cd-08d7e5f27472",
  "criteria":"absensi",
  "weight":21,
  "status":true
}
评论
  • 浅浅小鸣
    浅浅小鸣 回复
    const truc = 
          [ 
            { departmentID: "baccf1ba-d9ca-4480-46cd-08d7e5f27472"
            , criteria: "absensi"
            , weight: 21
            , status: true
            } 
          ] 
    
    const bidule = {...truc[0]}
    
    
    console.log(bidule)
  • 小情歌
    小情歌 回复
    JSONObject a = new JSONObject();
    
    JSONArray b = new JSONArray();
    
    b.put("arrayName", a);