List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void iterateAsBase64(final CallbackContext callbackContext, JSONArray args) { try {//from ww w. jav a 2 s. c o m String namespace = args.getString(0); Enumerator it1 = new Enumerator() { public int next() { JSONObject obj = new JSONObject(); try { obj.put(KEY, key); String base64 = Base64.encodeToString(data, Base64.NO_WRAP); obj.put(DATA, base64); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return Enumerator.Code.NONE; } }; mWinch.getNamespace(namespace).enumerate(it1); } catch (JSONException e1) { e1.printStackTrace(); } catch (WinchError e) { e.log(); PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage()); callbackContext.sendPluginResult(r); } PluginResult r = new PluginResult(PluginResult.Status.OK, false); r.setKeepCallback(false); callbackContext.sendPluginResult(r); }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private void drop(CallbackContext callbackContext, JSONArray args) { try {//from ww w . j a v a 2 s .c om mWinch.drop(args.getString(0)); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); } catch (WinchError e) { e.printStackTrace(); callbackContext.error(e.getErrorCode()); } }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private PluginResult buildProgressResult(int status, float progress, boolean keepCallback) { JSONObject obj = new JSONObject(); try {/* w ww . java 2s .c o m*/ obj.put(STATUS, status); obj.put(PROGRESS, progress); } catch (JSONException e) { e.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.OK, obj); r.setKeepCallback(keepCallback); return r; }
From source file:io.winch.phonegap.plugin.WinchPlugin.java
private PluginResult buildErrorResult(int errorCode, String errorMessage) { JSONObject obj = new JSONObject(); try {//from w w w. jav a2 s. c o m obj.put(CODE, errorCode); obj.put(MESSAGE, errorMessage); } catch (JSONException e1) { e1.printStackTrace(); } PluginResult r = new PluginResult(PluginResult.Status.ERROR, obj); r.setKeepCallback(false); return r; }
From source file:com.sina.weibo.sdk_lib.openapi.models.PoiList.java
public static PoiList parse(String jsonString) { if (TextUtils.isEmpty(jsonString)) { return null; }//from w ww . j a v a 2 s . com PoiList poiList = new PoiList(); try { JSONObject jsonObject = new JSONObject(jsonString); poiList.totalNumber = jsonObject.optString("total_number"); JSONArray jsonArray = jsonObject.optJSONArray("geos"); if (jsonArray != null && jsonArray.length() > 0) { int length = jsonArray.length(); poiList.pois = new ArrayList<Poi>(length); for (int ix = 0; ix < length; ix++) { poiList.pois.add(Poi.parse(jsonArray.optJSONObject(ix))); } } } catch (JSONException e) { e.printStackTrace(); } return poiList; }
From source file:github.nisrulz.sampleoptimushttp.MainActivity.java
private void getInfoFromJson(String msg) { JSONObject jsonObject;// ww w . jav a2 s .c o m try { jsonObject = new JSONObject(msg); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Name : ").append(jsonObject.getString("name")).append(" ") .append(jsonObject.getString("surname")).append("\n").append("Region : ") .append(jsonObject.getString("region")).append("\n").append("Gender : ") .append(jsonObject.getString("gender")).append("\n"); loadInfo(stringBuilder.toString()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:mo.iguideu.user.User.java
public User(GraphUser fbUser) { if (fbUser != null) { setName(fbUser.getName());//from w w w.j ava 2 s . c o m setBirthday(fbUser.getBirthday()); setFirstName(fbUser.getFirstName()); setLastName(fbUser.getLastName()); setFbLink(fbUser.getLink()); setMiddleName(fbUser.getMiddleName()); setUsername(fbUser.getId()); try { if (fbUser.getInnerJSONObject().get("locale") != null) setTimezone(fbUser.getInnerJSONObject().getString("timezone")); if (fbUser.getInnerJSONObject().get("locale") != null) setGender(fbUser.getInnerJSONObject().getString("gender").equals("male") ? true : false); if (fbUser.getInnerJSONObject().get("locale") != null) setLocale((String) fbUser.getInnerJSONObject().get("locale")); if (fbUser.getInnerJSONObject().get("location") != null) { setCity(fbUser.getLocation().getCity()); setCountry(fbUser.getLocation().getCountry()); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.example.nestedarchetypeactivityexample.InnerArchetypeViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try {/*from www. ja v a2 s . co m*/ // Provide an Archetype Schema Provider containing the informations about all the archetype schema used by the application) ArchetypeSchemaProvider asp = new ArchetypeSchemaProvider(getApplicationContext(), "archetypes.properties", "archetypes"); this.tp = new TemplateProvider(getApplicationContext(), WidgetProvider.parseFileToString(getApplicationContext(), "most_demo__template.json"), asp, LANGUAGE); this.buildArchetypeFragments(); this.setupButtonsListener(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.example.nestedarchetypeactivityexample.InnerArchetypeViewerActivity.java
private JSONArray getTemplateJsonContent() { List<WidgetProvider> wps = this.tp.getWidgetProviders(); JSONArray tmpJson = new JSONArray(); for (int i = 0; i < wps.size(); i++) try {//from ww w. ja v a2 s. c o m tmpJson.put(i, wps.get(i).toJson()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tmpJson; }
From source file:com.example.nestedarchetypeactivityexample.InnerArchetypeViewerActivity.java
private void setupButtonsListener() { Button butJson = (Button) findViewById(R.id.butJson); butJson.setOnClickListener(new OnClickListener() { @Override//from ww w . j a v a 2 s. co m public void onClick(View v) { String content; try { content = getTemplateJsonContent().toString(2); showInfoDialog(content); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); showInfoDialog(String.format("Error Parsing Json Content: \n\n %s", e.getMessage())); } } }); Button butSave = (Button) findViewById(R.id.butSave); butSave.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { submitTemplate(); } }); Button butReset = (Button) findViewById(R.id.butReset); butReset.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { resetTemplate(); } }); }