开发者

Need to convert JSON to an Array in same order

开发者 https://www.devze.com 2023-04-12 14:37 出处:网络
I need to use a huge JSON with 8000 elements (classes/subclasses) in it. I need to get it as a straight array (1-8000) in same sequence. Can i do with out creating classes?

I need to use a huge JSON with 8000 elements (classes/subclasses) in it. I need to get it as a straight array (1-8000) in same sequence. Can i do with out creating classes?

Dictionary object doesn't give me orderly items.

{
"Root":{
  "A":{
     "Q1":"1",
     "Q2":"2",
     "Q3":"3"
  },
  "B":{
     "Q1":"4",
     "Q2":"5",
     "Q3":"6"
  },
  "X":{
     "Y1":"11",
     "Y2":"22"
  }
},
"SUB":{
  "A":{
     "Q1":"10",
     "Q2":"20",
     "Q3":"30"开发者_JAVA百科
  },
  "X":{
     "Y1":"110",
     "Y2":"220"
  }
 }
}

Convert something like below array

  A-Q1,1
  A-Q2,2
  A-Q3,3
  B-Q1,4
  B-Q2,5
  B-Q3,6
  X-Y1,11
  X-Y2,22
  SUB-A-Q1,10
  SUB-A-Q2,20
  SUB-A-Q3,30
  SUB-X-Y1,110
  SUB-X-Y2,220


Since, in JSON:

An object is an unordered set of name/value pairs

Your options are:

  1. Change the source so it provides an array of objects instead of a set of key/value pairs
  2. Write a custom parser that doesn't treat it as JSON, but parses it into a data structure that you prefer
0

精彩评论

暂无评论...
验证码 换一张
取 消