mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
JSONObject and JSONArray initialization:
JSONObject(Map<String, ?> map) allows to initialize the JSONObject with a Map<String, String> JSONArray(Collection<?> collection) allows to initialize a JSONArray with a Collection<JSONObject>
This commit is contained in:
parent
b0191a6acf
commit
0afd26623c
2 changed files with 7 additions and 5 deletions
|
@ -151,10 +151,10 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* @param collection
|
* @param collection
|
||||||
* A Collection.
|
* A Collection.
|
||||||
*/
|
*/
|
||||||
public JSONArray(Collection<Object> collection) {
|
public JSONArray(Collection<?> collection) {
|
||||||
this.myArrayList = new ArrayList<Object>();
|
this.myArrayList = new ArrayList<Object>();
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
Iterator<Object> iter = collection.iterator();
|
Iterator<?> iter = collection.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
this.myArrayList.add(JSONObject.wrap(iter.next()));
|
this.myArrayList.add(JSONObject.wrap(iter.next()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,12 +243,14 @@ public class JSONObject {
|
||||||
* the JSONObject.
|
* the JSONObject.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject(Map<String, Object> map) {
|
public JSONObject(Map<String, ?> map) {
|
||||||
this.map = new HashMap<String, Object>();
|
this.map = new HashMap<String, Object>();
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Iterator<Entry<String, Object>> i = map.entrySet().iterator();
|
Set<?> eSet = map.entrySet();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Iterator<Entry<String, ?>> i = (Iterator<Entry<String, ?>>) eSet.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
Entry<String, Object> entry = i.next();
|
Entry<String, ?> entry = i.next();
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.map.put(entry.getKey(), wrap(value));
|
this.map.put(entry.getKey(), wrap(value));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue