Package com.google.appengine.repackaged.org.json

Examples of com.google.appengine.repackaged.org.json.JSONObject


    scanCount = (int) ((9 * scanCount) + (scanCount / time * targetRoundTime)) / 10;
    config.setScanCount(scanCount);
  }

  private Work fetchWork(Config config) throws IOException, JSONException {
    JSONObject getwork = new JSONObject();
    getwork.put("method", "getwork");
    getwork.put("params", new JSONArray());
    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());

    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      throw new IOException( //
          "fetchWork Error: " + resp.getResponseCode() + " "
              + content);
    }

    JSONObject respwork = new JSONObject(content);
    Object errorP = respwork.get("error");
    if (errorP != JSONObject.NULL) {
      JSONObject error = (JSONObject) errorP;
      throw new IOException( //
          "fetchWork Error: " + error.getString("message") //
              + " (" + error.getInt("code") + ")");
    }
    JSONObject result = respwork.getJSONObject("result");
    Work work = new Work( //
        result.getString("data"), //
        result.getString("hash1"), //
        result.getString("target"), //
        result.getString("midstate"));
    return work;
  }
View Full Code Here


    return work;
  }

  private boolean submitWork(Config config, Work work) throws JSONException,
      IOException {
    JSONObject getwork = new JSONObject();
    getwork.put("method", "getwork");
    getwork.append("params", work.data);
    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());
    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      log.severe( //
      "submitWork Error: " + resp.getResponseCode() + " " + content);
      return false;
    }

    JSONObject respwork = new JSONObject(content);
    Object errorP = respwork.get("error");
    if (errorP != JSONObject.NULL) {
      JSONObject error = (JSONObject) errorP;
      log.severe( //
      "submitWork Error: " + error.getString("message") //
          + " (" + error.getInt("code") + ")");
      return false;
    }

    return respwork.getBoolean("result");
  }
View Full Code Here

    try {
      jsonMap = SignedRequestDecoder.parse_signed_request(input, "f493dbd66eb6d4e668f17628ae52c514");
    } catch (Exception e1) {
    }
   
    JSONObject jsonObject = null;
    jsonObject = (JSONObject)jsonMap.get("registration");
   
    String name = "";
    String email = "";
    String userId = "";
   
    try {
      name = (String) jsonObject.get("name");
      email = (String) jsonObject.get("email");
      userId = (String)jsonMap.get("user_id");
    } catch (JSONException e) {
      e.printStackTrace();
    }
   
View Full Code Here

  }

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private static Map getMapOfJsonString(String DecMsg) throws JSONException {
    JSONObject jsonObject = null;

    try {
      jsonObject = new JSONObject(DecMsg);
    } catch (JSONException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    Map envelope = new HashMap<String, String>();

    String[] names = JSONObject.getNames(jsonObject);
    for (String name : names) {
      envelope.put(name, jsonObject.get(name));

    }
    return envelope;
  }
View Full Code Here

     * @param json the JSON string
     * @param modelReader the model reader
     */
    public JsonRootReader(String json, ModelReader modelReader){
        try{
            this.jsonObject = new JSONObject(json);
        } catch(JSONException e){
        }
        this.modelReader = modelReader;
    }
View Full Code Here

    }

    @Override
    public String readProperty(String name){
        if(array == null) return null;
        JSONObject o = array.optJSONObject(index);
        if(o == null) return null;
        return o.optString(name, null);
    }
View Full Code Here

     * Create the new JSONRootReader on the current index.
     *
     * @return JSONRootReader
     */
    public JsonRootReader newRootReader(){
        JSONObject o = array.optJSONObject(index);
        if(o == null) return null;
        return new JsonRootReader(o, getModelReader());
    }
View Full Code Here

        return object.optString(name, null);
    }

    @Override
    public String readProperty(String name){
        JSONObject o = object.optJSONObject(this.name);
        if(o == null) return null;
        return o.optString(name, null);
    }
View Full Code Here

        return array.optString(index, null);
    }

    @Override
    public String readProperty(String name){
        JSONObject o = array.optJSONObject(index);
        if(o == null) return null;
        return o.optString(name, null);
    }
View Full Code Here

     * @param json the JSON string
     * @param modelReader the model reader
     */
    public JsonRootReader(String json, ModelReader modelReader){
        try{
            this.jsonObject = new JSONObject(json);
        } catch(JSONException e){
        }
        this.modelReader = modelReader;
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.repackaged.org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.