Example usage for com.google.gson JsonObject JsonObject

List of usage examples for com.google.gson JsonObject JsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonObject JsonObject.

Prototype

JsonObject

Source Link

Usage

From source file:cn.com.caronwer.activity.AuthFirstActivity.java

private void getCheckCode() {
    String account = urgentContact.getText().toString();
    if (account.isEmpty()) {
        showShortToastByString("???");
        return;//from w  w w  .  ja v a  2s .c o  m
    }
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("Tel", account);
    Map<String, String> map = EncryptUtil.encryptDES(jsonObject.toString());

    HttpUtil.doPost(AuthFirstActivity.this, Contants.url_obtainCheckCode, "obtainCheckCode", map,
            new VolleyInterface(AuthFirstActivity.this, VolleyInterface.mListener,
                    VolleyInterface.mErrorListener) {
                @Override
                public void onSuccess(JsonElement result) {
                    isGetVerify = true;
                    Toast.makeText(AuthFirstActivity.this, "????", Toast.LENGTH_SHORT).show();

                    Message message = handler.obtainMessage(1); // Message
                    message.arg1 = 120;
                    handler.sendMessageDelayed(message, 1000); //
                }

                @Override
                public void onError(VolleyError error) {
                    Toast.makeText(AuthFirstActivity.this, "?", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onStateError(int sta, String msg) {
                    if (!TextUtils.isEmpty(msg)) {
                        showShortToastByString(msg);
                    }
                }
            });
}

From source file:cn.com.caronwer.activity.AuthFirstActivity.java

private void getVehicleTypes() {

    JsonObject mJsonObject = new JsonObject();
    Map<String, String> map = EncryptUtil.encryptDES(mJsonObject.toString());

    HttpUtil.doPost(AuthFirstActivity.this, Contants.url_getvehicletypes, "getvehicletypes", map,
            new VolleyInterface(AuthFirstActivity.this, VolleyInterface.mListener,
                    VolleyInterface.mErrorListener) {
                @Override/*from   ww  w .ja v  a  2s .c om*/
                public void onSuccess(JsonElement result) {
                    Gson gson = new Gson();
                    Type listType = new TypeToken<ArrayList<VehicleType>>() {
                    }.getType();
                    final ArrayList<VehicleType> vehicleTypes = gson
                            .fromJson(result.getAsJsonObject().get("VehicleTypeList"), listType);
                    ArrayAdapter<VehicleType> source = new ArrayAdapter<>(AuthFirstActivity.this,
                            android.R.layout.simple_spinner_dropdown_item, vehicleTypes);
                    vehicleType.setAdapter(source);
                    vehicleType.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                            VehType = vehicleTypes.get(arg2).getTypeCode();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {

                        }

                    });
                }

                @Override
                public void onError(VolleyError error) {
                }

                @Override
                public void onStateError(int sta, String msg) {
                    if (!TextUtils.isEmpty(msg)) {
                        showShortToastByString(msg);
                    }
                }
            });
}

From source file:cn.com.caronwer.activity.AuthSecondActivity.java

@Override
protected void initData() {
    getAuthInfo();//from   w w  w.  j  a  v a2  s.  c o m

    SharedPreferences prefs = getSharedPreferences(Contants.SHARED_NAME, MODE_PRIVATE);
    jsonObject = new JsonObject();
    //jsonObject.addProperty("VehNof", getIntent().getStringExtra("VehicleNo"));
    jsonObject.addProperty("UserID", prefs.getString("UserId", ""));
}

From source file:cn.com.caronwer.activity.AuthSecondActivity.java

private void getAuthInfo() {
    SharedPreferences prefs = getSharedPreferences(Contants.SHARED_NAME, MODE_PRIVATE);

    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("UserID", prefs.getString("UserId", ""));

    Map<String, String> map = EncryptUtil.encryptDES(jsonObject.toString());
    HttpUtil.doPost(AuthSecondActivity.this, Contants.url_TransporterGetVehicleCheck2, "GetVehicleCheck2", map,
            new VolleyInterface(AuthSecondActivity.this, VolleyInterface.mListener,
                    VolleyInterface.mErrorListener) {
                @Override//w  w w . j av a  2s . c  o  m
                public void onSuccess(JsonElement result) {
                    Gson gson = new Gson();
                    VehicleAuth2 vehicleAuth = gson.fromJson(result, VehicleAuth2.class);
                    setAuthInfo(vehicleAuth);
                }

                @Override
                public void onError(VolleyError error) {
                }

                @Override
                public void onStateError(int sta, String msg) {
                    if (!TextUtils.isEmpty(msg)) {
                        showShortToastByString(msg);
                    }
                }
            });
}

From source file:cn.com.caronwer.activity.CertificationActivity.java

@Override
protected void initView() {

    tv_title.setText("?");
    tv_right.setVisibility(View.GONE);
    iv_left_white.setOnClickListener(this);
    mPv_sfz.setOnClickListener(this);
    mPv_xsz.setOnClickListener(this);
    mPv_jsz.setOnClickListener(this);
    mPv_cl.setOnClickListener(this);
    mBv_next.setOnClickListener(this);
    mJsonObject = new JsonObject();

}

From source file:cn.com.caronwer.activity.CertificationActivity.java

/**
 * ?//from   ww  w. ja v  a2  s.c  om
 */

public void getVehicleTypes() {

    JsonObject mJsonObject = new JsonObject();
    Map<String, String> map = EncryptUtil.encryptDES(mJsonObject.toString());

    HttpUtil.doPost(CertificationActivity.this, Contants.url_getvehicletypes, "getvehicletypes", map,
            new VolleyInterface(CertificationActivity.this, VolleyInterface.mListener,
                    VolleyInterface.mErrorListener) {
                @Override
                public void onSuccess(JsonElement result) {
                    isChange = true;

                }

                @Override
                public void onError(VolleyError error) {
                }

                @Override
                public void onStateError(int sta, String msg) {
                    if (!TextUtils.isEmpty(msg)) {
                        showShortToastByString(msg);
                    }
                }
            });
}

From source file:cn.edu.zjnu.acm.judge.util.excel.ExcelUtil.java

License:Apache License

private static <T> T parseRow(FormulaEvaluator evaluator, Row row, Map<Integer, String> fields, Class<T> type) {
    JsonObject jsonObject = new JsonObject();
    for (Iterator<Cell> it = row.cellIterator(); it.hasNext();) {
        Cell cell = it.next();//from www  .j  a  v a  2  s . co m
        String name = fields.get(cell.getColumnIndex());
        if (name != null) {
            JsonElement cellValue = parseAsJsonElement(cell, evaluator);
            if (cellValue != null) {
                jsonObject.add(name, cellValue);
            }
        }
    }
    return GsonHolder.GSON.fromJson(jsonObject, type);
}

From source file:co.aikar.timings.TimingsExport.java

License:MIT License

/**
 * Builds a JSON timings report and sends it to Aikar's viewer
 *
 * @param sender Sender that issued the command
 *///from w ww .  j a va  2  s .  c om
public static void reportTimings(CommandSender sender) {
    JsonObject out = new JsonObject();
    out.addProperty("version", Server.getInstance().getVersion());
    out.addProperty("maxplayers", Server.getInstance().getMaxPlayers());
    out.addProperty("start", TimingsManager.timingStart / 1000);
    out.addProperty("end", System.currentTimeMillis() / 1000);
    out.addProperty("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);

    if (!Timings.isPrivacy()) {
        out.addProperty("server", Server.getInstance().getName());
        out.addProperty("motd", Server.getInstance().getMotd());
        out.addProperty("online-mode", false); //In MCPE we have permanent offline mode.
        out.addProperty("icon", ""); //"data:image/png;base64,"
    }

    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

    JsonObject system = new JsonObject();
    system.addProperty("timingcost", getCost());
    system.addProperty("name", System.getProperty("os.name"));
    system.addProperty("version", System.getProperty("os.version"));
    system.addProperty("jvmversion", System.getProperty("java.version"));
    system.addProperty("arch", System.getProperty("os.arch"));
    system.addProperty("maxmem", runtime.maxMemory());
    system.addProperty("cpu", runtime.availableProcessors());
    system.addProperty("runtime", ManagementFactory.getRuntimeMXBean().getUptime());
    system.addProperty("flags", String.join(" ", runtimeBean.getInputArguments()));
    system.add("gc",
            JsonUtil.mapToObject(ManagementFactory.getGarbageCollectorMXBeans(),
                    (input) -> new JsonUtil.JSONPair(input.getName(),
                            JsonUtil.toArray(input.getCollectionCount(), input.getCollectionTime()))));
    out.add("system", system);

    TimingsHistory[] history = HISTORY.toArray(new TimingsHistory[HISTORY.size() + 1]);
    history[HISTORY.size()] = new TimingsHistory(); //Current snapshot

    JsonObject timings = new JsonObject();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
        for (Timing id : group.timings.stream().toArray(Timing[]::new)) {
            if (!id.timed && !id.isSpecial()) {
                continue;
            }

            timings.add(String.valueOf(id.id), JsonUtil.toArray(group.id, id.name));
        }
    }

    JsonObject idmap = new JsonObject();
    idmap.add("groups", JsonUtil.mapToObject(TimingIdentifier.GROUP_MAP.values(),
            (group) -> new JsonUtil.JSONPair(group.id, group.name)));
    idmap.add("handlers", timings);
    idmap.add("worlds", JsonUtil.mapToObject(TimingsHistory.levelMap.entrySet(),
            (entry) -> new JsonUtil.JSONPair(entry.getValue(), entry.getKey())));
    idmap.add("tileentity", JsonUtil.mapToObject(TimingsHistory.blockEntityMap.entrySet(),
            (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    idmap.add("entity", JsonUtil.mapToObject(TimingsHistory.entityMap.entrySet(),
            (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    out.add("idmap", idmap);

    //Information about loaded plugins
    out.add("plugins",
            JsonUtil.mapToObject(Server.getInstance().getPluginManager().getPlugins().values(), (plugin) -> {
                JsonObject jsonPlugin = new JsonObject();
                jsonPlugin.addProperty("version", plugin.getDescription().getVersion());
                jsonPlugin.addProperty("description", plugin.getDescription().getDescription());// Sounds legit
                jsonPlugin.addProperty("website", plugin.getDescription().getWebsite());
                jsonPlugin.addProperty("authors", String.join(", ", plugin.getDescription().getAuthors()));
                return new JsonUtil.JSONPair(plugin.getName(), jsonPlugin);
            }));

    //Information on the users Config
    JsonObject config = new JsonObject();
    if (!Timings.getIgnoredConfigSections().contains("all")) {
        JsonObject nukkit = JsonUtil.toObject(Server.getInstance().getConfig().getRootSection());
        Timings.getIgnoredConfigSections().forEach(nukkit::remove);
        config.add("nukkit", nukkit);
    } else {
        config.add("nukkit", null);
    }
    out.add("config", config);

    new TimingsExport(sender, out, history).start();
}

From source file:co.aikar.timings.TimingsHistory.java

License:MIT License

JsonObject export() {
    JsonObject json = new JsonObject();
    json.addProperty("s", this.startTime);
    json.addProperty("e", this.endTime);
    json.addProperty("tk", this.totalTicks);
    json.addProperty("tm", this.totalTime);
    json.add("w", this.levels);
    json.add("h", JsonUtil.mapToArray(this.entries, (entry) -> {
        if (entry.data.count == 0) {
            return null;
        }/*from  w  ww  . j a v a  2  s  .  c  o m*/
        return entry.export();
    }));
    json.add("mp", JsonUtil.mapToArray(this.minuteReports, MinuteReport::export));
    return json;
}

From source file:co.cask.cdap.api.dataset.lib.ConditionCodec.java

License:Apache License

@Override
public JsonElement serialize(PartitionFilter.Condition condition, Type type,
        JsonSerializationContext jsonSerializationContext) {
    JsonObject jsonObj = new JsonObject();
    jsonObj.addProperty("fieldName", condition.getFieldName());
    jsonObj.add("lower", serializeComparable(condition.getLower(), jsonSerializationContext));
    jsonObj.add("upper", serializeComparable(condition.getUpper(), jsonSerializationContext));
    jsonObj.addProperty("isSingleValue", condition.isSingleValue());
    return jsonObj;
}