私はjsonを生成するためにいくつかのjspを書きますが、あるケースでは、私は問題を満たしています。 私は順序を入れて順序が同じではない、 jsonarrayに1,2,3,4,5を入れました。私に私のコードは、JSPである間違った順序3,2,5,1,4 を返す:JSONArrayの注文方法は?
Map map = new LinkedHashMap();
Iterator itor = listView.getList().iterator();
JSONObject json = new JSONObject();
JSONArray jArray = new JSONArray();
while (itor.hasNext()) {
current = (EvidPackageDao) itor.next();
map.put("id", current.getPackageId());
map.put("packno", current.getPackageNo());
map.put("photocover", current.getPhotoCover());
map.put("photoback", current.getPhotoBack());
map.put("evidi", current.getEvidIndentification());
map.put("type", current.getEvidType());
map.put("verno", current.getVersionNo());
map.put("isbn", current.getIsbn());
map.put("pub", current.getPublisher());
map.put("distr", current.getDistributor());
map.put("producer", current.getProducer());
map.put("cprl", current.getCoptrightLogo());
map.put("cprt", current.getCopyrightText());
map.put("reason", current.getIllegalReason());
Iterator it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println("key=" + key + ", value=" + value);
}
/*
print:
key=id, value=81
key=packno, value=fsdfdsfsdf
key=photocover, value=null
key=photoback, value=null
key=evidi, value=sdfsadf
key=type, value=dsfsdf
key=verno, value=sdfasdfl
key=isbn, value=3224jsfklf
key=pub, value=fdsjkla
key=distr, value=lkfjl;dsfklj
key=producer, value=fdafjdsl;
key=cprl, value=sdfjadlfkj
key=cprt, value=sdfadff
key=reason, value=fdsfdsafasf
*/
jArray.put(map);
System.out.println(jArray.toString());
/*
print:
[{"reason":null,"distr":null,"type":null,"pub":null,"verno":null,"id":82,"cprl":null,"isbn":null,"evidi":null,"photoback":null,"producer":null,"packno":null,"photocover":null,"cprt":null},{"reason":"fdsfdsafasf","distr":"lkfjl;dsfklj","type":"dsfsdf","pub":"fdsjkla","verno":"sdfasdfl","id":81,"cprl":"sdfjadlfkj","isbn":"3224jsfklf","evidi":"sdfsadf","photoback":null,"producer":"fdafjdsl;","packno":"fsdfdsfsdf","photocover":null,"cprt":"sdfadff"}]
*/
}
ので、私はハッシュマップに私のPUTと同じ右の順番を得ることができますか?????? ? [{"" id ":null、?
注文をしたいたのはなぜ? LinkedHashMapは、あなたが入れた要素の順序を保持していません – janwen