Beispiel #1
0
def parse_json(response):
    if response.startswith('['):
        json_arr = JSONArray(response)
        return [
            json_arr.getJSONObject(i) for i in xrange(0, json_arr.length())
        ]
    return JSONObject(response)
 def testConvertDirtyQueryToPstmt(self):
     """ Make sure we can convert some raw SQL into a prepared statement
     even if it contains some regex borking chars. """
     query  = "select dollars from dual where 1 = 1 and x = 1.0 and r = '$500.00' "
     values = JSONArray()
     nQuery = QueryExecutor.convertQueryToPstmt(query, values)
     assert(nQuery == "select dollars from dual where ? = ? and x = ? and r = ? ")
     assert(values.toString() == '["1","1","1.0","\\\$500.00"]')            
 def testConvertQueryToPstmt(self):
     """ Make sure we can convert some raw SQL into a 
     prepared statement """
     query  = "select sysdate from dual where 1 = 1 and x = 1.0 and r = 'test' "
     values = JSONArray()
     nQuery = QueryExecutor.convertQueryToPstmt(query, values)
     assert(nQuery == "select sysdate from dual where ? = ? and x = ? and r = ? ")
     assert(values.toString() == '["1","1","1.0","test"]')
Beispiel #4
0
def listToJsonArray(d):
    json = JSONArray()
    for item in d:
        if isinstance(item, dict):
            value = dictToJsonObject(item)
        else:
            value = listToJsonArray(item)
        json.put(value)

    return json
Beispiel #5
0
 def fromMap(cls, obj):
     if isinstance(obj, dict):
         jsonObject = JSONObject()
         for k in obj:
             jsonObject.put(k, cls.fromMap(obj[k]))
         return jsonObject
     elif isinstance(obj, list):
         jsonArray = JSONArray()
         for k in obj:
             jsonArray.put(k)
         return jsonArray
     else:
         return obj
Beispiel #6
0
 def fromMap(cls, obj):
     if isinstance(obj, dict):
         jsonObject = JSONObject()
         for k in obj:
             jsonObject.put(k, cls.fromMap(obj[k]))
         return jsonObject
     elif isinstance(obj, list):
         jsonArray = JSONArray()
         for k in obj:
             jsonArray.put(k)
         return jsonArray
     else:
         return obj
Beispiel #7
0
def loads(s):
    if s.startswith('{'):
        objJson = JSONObject(s)
        python_json = jsonObjToDict(objJson)
    else:
        arrayjson = JSONArray(s)
        python_json = jsonArrayToDict(arrayjson)

    return python_json
def layerToJSON(layer):
    jsonlayer = JSONObject()
    jsonfeatures = JSONArray()
    ftype = layer.getFeatureStore().getDefaultFeatureType()
    geomAttributeName = ftype.getDefaultGeometryAttributeName()
    for f in layer.getFeatureStore().getFeatureSet():
        jsonfeature = JSONObject()
        values = f.getValues()
        for k in values.keys():
            value = values[k]
            if k == geomAttributeName:
                wkt = value.convertToWKT()
                jsonfeature.putOnce(k, wkt)
            else:
                jsonfeature.putOnce(k, value)
        jsonfeatures.put(jsonfeature)
    jsonlayer.put("features", jsonfeatures)
    return jsonlayer
Beispiel #9
0
 def decode(self, buffer):
     try:
         if buffer == '':
             return buffer
         elif buffer[0] == '{':
             return JSONObject(buffer)
         elif buffer[0] == '[':
             return JSONArray(buffer)
         else:
             return buffer
     except JException, je:
         return buffer
Beispiel #10
0
            }
            JSONObject jSONObject = (JSONObject) jSONArray.opt(i2);
            if (jSONObject != null) {
                arrayList.add(jSONObject.optString("type") + "://" + jSONObject.optString("ip") + ":" + jSONObject.optString(ClientCookie.PORT_ATTR));
            }
            i = i2 + 1;
        }
    }

    /* renamed from: g */
    private void m8523g() {
        SharedPreferences sharedPreferences = this.f4588n.getSharedPreferences(f4575a, 0);
        String string = sharedPreferences.getString("PortalSrvList", "[{\"port\":\"443\",\"type\":\"https\",\"ip\":\"119.147.41.25\"}]");
        String string2 = sharedPreferences.getString("LoginSrvList", "[{\"port\":\"443\",\"type\":\"https\",\"ip\":\"123.150.173.56\"},{\"port\":\"443\",\"type\":\"https\",\"ip\":\"119.147.41.25\"},{\"port\":\"443\",\"type\":\"https\",\"ip\":\"125.39.70.56\"}]");
        try {
            List a = m8509a(new JSONArray(string));
            a.add(0, "https://login.mobile.reg2t.sandai.net:443");
            this.f4582h.put(Integer.valueOf(7), a);
            List a2 = m8509a(new JSONArray(string2));
            a2.add(0, "https://login.mobile.reg2t.sandai.net:443");
            this.f4582h.put(Integer.valueOf(1), a2);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        ArrayList arrayList = new ArrayList();
        arrayList.add(0, "http://dy.cdn.vip.xunlei.com:80/fcg-bin/cgi_query_capacity.fcg?userid=");
        this.f4582h.put(Integer.valueOf(9), arrayList);
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(0, "http://dynamic.cloud.vip.xunlei.com/interface/query_user_info?uid=");
        this.f4582h.put(Integer.valueOf(10), arrayList2);
    }
Beispiel #11
0
def parse_json(response):
    if response.startswith('['):
        json_arr = JSONArray(response)
        return [json_arr.getJSONObject(i) for i in xrange(0, json_arr.length())]
    return JSONObject(response)