package com.ironsource; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public class wp { private JSONObject a; public wp() { this.a = new JSONObject(); } public wp(String str) { f(str); } private Object a(Object obj) throws JSONException { if (obj == JSONObject.NULL) { return null; } return obj instanceof JSONObject ? b((JSONObject) obj) : obj instanceof JSONArray ? a((JSONArray) obj) : obj; } public static boolean a(JSONObject jSONObject) { return jSONObject.names() == null; } public static Object b(Object obj) throws JSONException { if (!(obj instanceof Map)) { if (!(obj instanceof Iterable)) { return obj; } JSONArray jSONArray = new JSONArray(); Iterator it = ((Iterable) obj).iterator(); while (it.hasNext()) { jSONArray.put(it.next()); } return jSONArray; } JSONObject jSONObject = new JSONObject(); Map map = (Map) obj; for (Object obj2 : map.keySet()) { if (obj2 != null) { jSONObject.put(obj2.toString(), b(map.get(obj2))); } } return jSONObject; } private Map b(JSONObject jSONObject) throws JSONException { HashMap hashMap = new HashMap(); Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); hashMap.put(next, a(jSONObject.get(next))); } return hashMap; } private void f(String str) { try { this.a = new JSONObject(str); } catch (Exception e) { i9.d().a(e); this.a = new JSONObject(); } } public int a(String str, int i) { return this.a.optInt(str, i); } public String a(String str, String str2) { return this.a.optString(str, str2); } public List a(JSONArray jSONArray) throws JSONException { ArrayList arrayList = new ArrayList(); for (int i = 0; i < jSONArray.length(); i++) { arrayList.add(a(jSONArray.get(i))); } return arrayList; } public JSONObject a() { return this.a; } public void a(String str, JSONObject jSONObject) { try { this.a.put(str, jSONObject); } catch (Exception e) { i9.d().a(e); } } public boolean a(String str) { return a().has(str); } public Object b(String str) { try { return a().get(str); } catch (JSONException e) { i9.d().a(e); return null; } } public void b(String str, String str2) { try { this.a.put(str, str2); } catch (Exception e) { i9.d().a(e); } } public boolean c(String str) { return this.a.optBoolean(str); } public String d(String str) { return this.a.optString(str, null); } public boolean e(String str) { return a().isNull(str); } public String toString() { JSONObject jSONObject = this.a; return jSONObject == null ? "" : jSONObject.toString(); } }