Search in sources :

Example 96 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class LinkRepositoryImpl method getByAddress.

@Override
public JSONObject getByAddress(final String address) throws RepositoryException {
    final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address)).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 97 with JSONArray

use of org.json.JSONArray in project h2o-2 by h2oai.

the class h2oService method ImportCSVFile.

public String ImportCSVFile(String path) {
    //example - url http://localhost:54321/2/ImportFiles2.json?path=%2Ftmp%2Fetsy_images%2Fimage_deep_features_csv#
    String key;
    String h2oUrlImportEndPoint = H2O_HOST_URL + H2O_IMPORT_URL + path;
    log.debug("@@@ Calling endpoint {}", h2oUrlImportEndPoint);
    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject(h2oUrlImportEndPoint, String.class);
    //{"Request2":0,"response_info":{"h2o":"paragsanghavi","node":"/172.16.2.45:54321","time":1,
    // "status":"done","redirect_url":null},"prefix":"nfs://tmp/etsy_images/deep_features_csv",
    // "files":["/tmp/etsy_images/deep_features_csv"],"keys":["nfs://tmp/etsy_images/deep_features_csv"],
    // "fails":[],"dels":["nfs://tmp/etsy_images/deep_features_csv"]}
    log.debug("@@@ Response json from h2o {}", result);
    JSONObject jsonobject = new JSONObject(result);
    JSONObject response_info = (JSONObject) jsonobject.get("response_info");
    String status = (String) response_info.get("status");
    log.debug("!!!!!! Import Status  {}", status);
    if (status.equalsIgnoreCase("DONE")) {
        JSONArray jsonarray = (JSONArray) jsonobject.get("keys");
        key = (String) jsonarray.get(0);
        System.out.println("!!!!!! Import key : " + key);
        log.debug("!!!!!! Import key  {}", key);
        return key;
    } else {
        return "error";
    }
}
Also used : JSONObject(org.json.JSONObject) RestTemplate(org.springframework.web.client.RestTemplate) JSONArray(org.json.JSONArray)

Example 98 with JSONArray

use of org.json.JSONArray in project facebook-android-sdk by facebook.

the class TestUserManagerTests method countTestUsers.

private int countTestUsers() {
    TestUserManager testUserManager = createTestUserManager();
    String appAccessToken = testUserManager.getAppAccessToken();
    assertNotNull(appAccessToken);
    Bundle parameters = new Bundle();
    parameters.putString("access_token", appAccessToken);
    parameters.putString("fields", "id");
    GraphRequest requestTestUsers = new GraphRequest(null, "app/accounts/test-users", parameters, null);
    GraphResponse response = requestTestUsers.executeAndWait();
    JSONArray data = response.getJSONObject().optJSONArray("data");
    return data.length();
}
Also used : Bundle(android.os.Bundle) JSONArray(org.json.JSONArray)

Example 99 with JSONArray

use of org.json.JSONArray in project facebook-android-sdk by facebook.

the class RequestTests method validateMyFriendsResponse.

static void validateMyFriendsResponse(GraphResponse response) {
    assertNotNull(response);
    assertNull(response.getError());
    JSONObject graphResult = response.getJSONObject();
    assertNotNull(graphResult);
    JSONArray results = graphResult.optJSONArray("data");
    assertNotNull(results);
    assertNotNull(response.getRawResponse());
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 100 with JSONArray

use of org.json.JSONArray in project facebook-android-sdk by facebook.

the class RequestTests method testExecutePlaceRequestWithSearchText.

@LargeTest
public void testExecutePlaceRequestWithSearchText() {
    // Pass a distance without a location to ensure it is correctly ignored.
    GraphRequest request = GraphRequest.newPlacesSearchRequest(AccessToken.getCurrentAccessToken(), null, 1000, 5, "Starbucks", null);
    GraphResponse response = request.executeAndWait();
    assertNotNull(response);
    assertNull(response.getError());
    JSONObject graphResult = response.getJSONObject();
    assertNotNull(graphResult);
    JSONArray results = graphResult.optJSONArray("data");
    assertNotNull(results);
    assertNotNull(response.getRawResponse());
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

JSONArray (org.json.JSONArray)1707 JSONObject (org.json.JSONObject)1188 JSONException (org.json.JSONException)735 ArrayList (java.util.ArrayList)323 IOException (java.io.IOException)241 Test (org.junit.Test)207 HashMap (java.util.HashMap)108 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)96 List (java.util.List)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 HashSet (java.util.HashSet)54 File (java.io.File)53 Date (java.util.Date)47 Query (org.b3log.latke.repository.Query)47 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)43 FileNotFoundException (java.io.FileNotFoundException)40 Map (java.util.Map)40 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)36 VolleyError (com.android.volley.VolleyError)35