首页 > 解决方案 > 将 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
}

标签: javascript

解决方案


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

const bidule = {...truc[0]}


console.log(bidule)


推荐阅读