0

JSON String FormlinkedHashMap を生成するにはどうすればよいですか。

マップには (1,aaa) (2,bbb), (3,ccc) が含まれています...これから Json 文字列を生成する必要があります

{ {id:1,text:"aaa"},{id:2,text:"bbb"},{id:3,text:"ccc"},...}

誰でもこれを修正するのを手伝ってください。

4

1 に答える 1

0

In javascript a map is acutally pretty much the same as a classical object:

{ "1": "aaa", "2":"bbb","3":"ccc",... }

I am not 100% sure you can use numbers as keys...

an alternative would be to use a structure like this and have an array of objects:

[ {id:1,text:"aaa"},{id:2,text:"bbb"},{id:3,text:"ccc"},... ]

or to be more in the spirit of a map, you should name the fields "map-like":

[ {key:1,value:"aaa"},{key:2,value:"bbb"},{key:3,value:"ccc"},... ]

All 3 are valid json/javascript forms, which one suits you best depends on what you actually want to use it for.

于 2013-10-06T07:59:32.490 に答える