solr - How to transform SimpleOrderedMap into JSON string or JSON object? -


is there standard way so?

in short: no, because json doesn't have primitive ordered map type.

the first step determine requirements of client, far decoding json string goes. since json specification doesn't have ordered map type, you'll have decide on representation use. choice make depend on decoding requirements of client.

if have full control on decoding of json string, can encode object map in order, using json library guaranteed serialize things in order of iterator pass in.

if can't guarantee this, should come representation on own. 2 simple examples are:

an alternating list:

 "[key1, value1, key2, value2]" 

a list of key/value entry objects:

 "[{key: key1, val:value1}, {key: key2, val:value2}]" 

once you've come representation, it's easy write simple function loops on simpleorderedmap. example :

 jsonarray jarray = new jsonarray(); for(map.entry e : simpleorderedmap) {     jarray.put(e.key());     jarray.put(e.value()); } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -