本文介绍了放置HashMap< String,object>在jsonobject中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我构建了一个由在Hashmap中定义的nameValue对组成的json对象。
我遇到的问题是当我调用时: jsonObject.put(hashmap);
它添加nameValue对,如下所示:
name = value
而不是 name:value
任何想法?
谢谢
解决方案
迭代HashMap和放到jsonObject中:
Iterator it = mp.entrySet()。iterator(); (it.hasNext()){
Map.Entry pairs =(Map.Entry)it.next();
jsonObject.put(pairs.getKey(),pairs.getValue());
}
i building a json object that consists of nameValue pairs defined in a Hashmap
the issue i am having is when i invoke:
jsonObject.put(hashmap);
It adds the nameValue pairs like this:
name=value
instead of name:value
Any thoughts?
Thanks
解决方案
Iterate through the HashMap and put to the jsonObject:
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
jsonObject.put(pairs.getKey(), pairs.getValue() );
}
这篇关于放置HashMap< String,object>在jsonobject中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!