How to represent a sparse array in JSON?

后端 未结 2 1676
一个人的身影
一个人的身影 2021-01-13 06:18

I\'ve got a sparse array that I want to represent in JSON. For example:

  -10 => 100
   -1 => 102
    3 => 44
   12 => -87
12345 => 0
<         


        
2条回答
  •  半阙折子戏
    2021-01-13 06:40

    Yes, you can. JSON object members name are strings. Strings can hold any UTF-8 encoded value:

    {
      "-10"   : 100,
      "-1"    : 102,
      "3"     : 44,
      "12"    : -87,
      "12345" : 0
    }
    

提交回复
热议问题