类JSON字符串根据层级关系合并

已知有两有层级关系的类似JSON的字符串,无法转成对象,怎么让他们合并。

代码如下:

var str1 = "data : {
  item : ( payload.data.list map(value0, index0) -> {
    gradeList : ( value0.gradeList map(value1, index1) -> {
      otherList : ( value1.otherList map(value2, index2) -> {
        anotherList : ( value2.anotherList map(value3, index3) -> { name: value3.name })
      })
    })
  })
}"

var str2 = "data : {
  item : ( payload.data.list map(value0, index0) -> {
    gradeList : ( value0.gradeList map(value1, index1) -> {
      otherList : ( value1.otherList map(value2, index2) -> { name: value2.name })
    })
  })
}"

可以看出str1中的anotherList,在str2中的otherList里面

希望得到如下结果

"{
  data: {
    list: (payload.data.list map (value0, index0) -> {
      gradeList: (value0.gradeList map (value1, index1) -> {
        otherList: (value1.otherList map (value2, index2) -> {
          anotherList: (value2.anotherList map (value3, index3) -> {
            name: value3.name
          }),
          name: value2.name
        })
      })
    })
  }
}"
阅读 1.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题