List of usage examples for org.json JSONTokener nextValue
public Object nextValue() throws JSONException
From source file:org.araqne.docxcod.test.DocxTest.java
@Test public void arbitraryTableTest() throws IOException, JSONException { File targetDir = new File(".test/_abtrTableTest"); File saveFile = new File(".test/abtrTableTest-save.docx"); saveFile.delete();/* w w w. j a v a 2 s .c om*/ targetDir.mkdirs(); // tearDownHelper.add(targetDir); OOXMLPackage docx = new OOXMLPackage(); docx.load(getClass().getResourceAsStream("/abtrTableTest.docx"), targetDir); docx.setOutputStream(new FileOutputStream(saveFile)); InputStreamReader inputReader = new InputStreamReader(getClass().getResourceAsStream("/abtrTableTest.in"), Charset.forName("utf-8")); JSONTokener tokener = new JSONTokener(inputReader); Map<String, Object> rootMap = JsonHelper.parse((JSONObject) tokener.nextValue()); List<OOXMLProcessor> processors = new ArrayList<OOXMLProcessor>(); docx.apply(new MergeFieldParser(), rootMap); docx.apply(new DirectivePlacerProcessor(), rootMap); docx.apply(new AbtrTableDirectiveParser(), rootMap); docx.apply(new ChartDirectiveParser(), rootMap); docx.apply(new MagicNodeUnwrapper("word/document.xml"), rootMap); docx.apply(new FreeMarkerRunner("word/document.xml"), rootMap); docx.close(); // tearDownHelper.add(saveFile); }
From source file:org.araqne.docxcod.test.DocxTest.java
@Test public void chartTest() throws IOException, JSONException { File targetDir = new File(".test/_chartTest"); File saveFile = new File(".test/chartTest-save.docx"); targetDir.mkdirs();//from www . j ava 2 s . co m saveFile.delete(); // tearDownHelper.add(targetDir); OOXMLPackage docx = new OOXMLPackage(); docx.load(getClass().getResourceAsStream("/chartTest.docx"), targetDir); docx.setOutputStream(new FileOutputStream(saveFile)); InputStreamReader inputReader = new InputStreamReader(getClass().getResourceAsStream("/nestedListTest.in")); JSONTokener tokener = new JSONTokener(inputReader); Map<String, Object> rootMap = JsonHelper.parse((JSONObject) tokener.nextValue()); List<OOXMLProcessor> processors = new ArrayList<OOXMLProcessor>(); processors.add(new MergeFieldParser()); processors.add(new DirectivePlacerProcessor()); processors.add(new ChartDirectiveParser()); // processors.add(new ImgDirectiveParser()); processors.add(new MagicNodeUnwrapper("word/document.xml")); processors.add(new FreeMarkerRunner("word/document.xml")); docx.apply(processors, rootMap); docx.setDebug(true); docx.close(); }
From source file:org.araqne.docxcod.test.DocxTest.java
@Test public void mainTest() throws IOException, JSONException { File targetDir = new File(".test/mainTest"); File saveFile = new File(".test/mainTest-save.docx"); saveFile.delete();//from www . j av a 2 s . c o m targetDir.mkdirs(); OOXMLPackage docx = new OOXMLPackage(); docx.load(getClass().getResourceAsStream("/nestedList2.docx"), targetDir); docx.setOutputStream(new FileOutputStream(saveFile)); docx.setDebug(true); InputStreamReader inputReader = new InputStreamReader(getClass().getResourceAsStream("/nestedListTest.in")); JSONTokener tokener = new JSONTokener(inputReader); Map<String, Object> rootMap = JsonHelper.parse((JSONObject) tokener.nextValue()); List<OOXMLProcessor> processors = new ArrayList<OOXMLProcessor>(); processors.add(new MergeFieldParser()); processors.add(new DirectivePlacerProcessor()); processors.add(new MagicNodeUnwrapper("word/document.xml")); processors.add(new FreeMarkerRunner("word/document.xml")); docx.apply(processors, rootMap); docx.setDebug(true); docx.close(); }
From source file:my.home.lehome.receiver.LocalMessageReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(LOCAL_MSG_RECEIVER_ACTION)) { if (PrefUtil.getbooleanValue(context, MainActivityPresenter.APP_EXIT_KEY, false)) { Log.d(TAG, "app set exit. ignore network state change."); return; }/* w w w .j a v a 2 s . c o m*/ String lm = intent.getStringExtra(LOCAL_MSG_REP_KEY); Log.d(TAG, "receive local msg: " + lm); if (lm != null) { JSONTokener jsonParser = new JSONTokener(lm); String type = ""; String msg = ""; String err_msg = ""; int seq = -1; try { JSONObject cmdObject = (JSONObject) jsonParser.nextValue(); type = cmdObject.getString("type"); msg = cmdObject.getString("msg"); seq = cmdObject.getInt("seq"); if (MessageHelper.enqueueMsgSeq(context, seq)) return; } catch (JSONException e) { e.printStackTrace(); err_msg = context.getString(R.string.msg_push_msg_format_error); } catch (Exception e) { e.printStackTrace(); err_msg = context.getString(R.string.msg_push_msg_format_error); } if (!TextUtils.isEmpty(err_msg)) { MessageHelper.sendToast(err_msg); return; } if (type.equals("req_loc") || type.equals("req_geo")) { LocationHelper.enqueueLocationRequest(context, seq, type, msg); return; } else if (Arrays.asList(MessageHelper.NORMAIL_FILTER_TAG_LIST).contains(type)) { MessageHelper.inNormalState = true; } else if (type.equals("toast")) { MessageHelper.sendToast(msg); return; } else { MessageHelper.inNormalState = false; } MessageHelper.sendServerMsgToList(seq, type, msg, context); } } }
From source file:info.axbase.app.VersionInfo.java
public static VersionInfo parse(String text) throws JSONException { JSONTokener jsonParser = new JSONTokener(text); JSONObject msg = (JSONObject) jsonParser.nextValue(); if (msg == null) { return null; }//from w w w .ja v a 2s. c o m if (msg.optInt("error") == 0) { JSONObject data = msg.optJSONObject("data"); if (data == null) { return null; } VersionInfo versionInfo = new VersionInfo(); versionInfo.fileName = data.optString("fileName"); versionInfo.whatsNew = data.optString("whatsNew"); versionInfo.fileTime = data.optLong("fileTime"); versionInfo.fileSize = data.optLong("fileSize"); versionInfo.appProject = data.optString("appProject"); versionInfo.digest = data.optString("digest"); versionInfo.version = data.optString("version"); return versionInfo; } else { Log.e("ParseError", msg.optString("msg")); return null; } }
From source file:my.home.lehome.receiver.RemoteMessageReceiver.java
public void onMessage(Context context, String message) { if (PrefUtil.getbooleanValue(context, MainActivityPresenter.APP_EXIT_KEY, false)) { Log.d(TAG, "app set exit. ignore network state change."); return;//from www.ja va 2 s .c o m } JSONTokener jsonParser = new JSONTokener(message); String type = ""; String msg = ""; String err_msg = ""; int seq = -1; try { JSONObject cmdObject = (JSONObject) jsonParser.nextValue(); type = cmdObject.getString("type"); msg = cmdObject.getString("msg"); seq = cmdObject.getInt("seq"); if (MessageHelper.enqueueMsgSeq(context, seq)) return; } catch (JSONException e) { e.printStackTrace(); err_msg = context.getString(R.string.msg_push_msg_format_error); } catch (Exception e) { e.printStackTrace(); err_msg = context.getString(R.string.msg_push_msg_format_error); } if (!TextUtils.isEmpty(err_msg)) { MessageHelper.sendToast(err_msg); return; } if (type.equals("req_loc") || type.equals("req_geo")) { LocationHelper.enqueueLocationRequest(context, seq, type, msg); return; } else if (Arrays.asList(MessageHelper.NORMAIL_FILTER_TAG_LIST).contains(type)) { MessageHelper.inNormalState = true; } else if (type.equals("toast")) { MessageHelper.sendToast(msg); return; } else { MessageHelper.inNormalState = false; } MessageHelper.sendServerMsgToList(seq, type, msg, context); }
From source file:com.gmx.library.JsonUtils.java
public static JSONObject string2JSONObject(String json) { JSONObject jsonObject = null;//from ww w .j a va 2 s .c om try { JSONTokener jsonParser = new JSONTokener(json); jsonObject = (JSONObject) jsonParser.nextValue(); } catch (Exception e) { e.printStackTrace(); } return jsonObject; }
From source file:org.apache.oltu.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper.java
public Map<String, String[]> getParameterMap() { if (!bodyRead) { String body = readJsonBody(); final JSONTokener x = new JSONTokener(body); char c;/*w w w . ja v a2s .c om*/ String key; if (x.nextClean() != '{') { throw new OAuthRuntimeException(format( "String '%s' is not a valid JSON object representation, a JSON object text must begin with '{'", body)); } for (;;) { c = x.nextClean(); switch (c) { case 0: throw new OAuthRuntimeException(format( "String '%s' is not a valid JSON object representation, a JSON object text must end with '}'", body)); case '}': return Collections.unmodifiableMap(parameters); default: x.back(); key = x.nextValue().toString(); } /* * The key is followed by ':'. We will also tolerate '=' or '=>'. */ c = x.nextClean(); if (c == '=') { if (x.next() != '>') { x.back(); } } else if (c != ':') { throw new OAuthRuntimeException(format( "String '%s' is not a valid JSON object representation, expected a ':' after the key '%s'", body, key)); } Object value = x.nextValue(); // guard from null values if (value != null) { if (value instanceof JSONArray) { // only plain simple arrays in this version JSONArray array = (JSONArray) value; String[] values = new String[array.length()]; for (int i = 0; i < array.length(); i++) { values[i] = String.valueOf(array.get(i)); } parameters.put(key, values); } else { parameters.put(key, new String[] { String.valueOf(value) }); } } /* * Pairs are separated by ','. We will also tolerate ';'. */ switch (x.nextClean()) { case ';': case ',': if (x.nextClean() == '}') { return Collections.unmodifiableMap(parameters); } x.back(); break; case '}': return Collections.unmodifiableMap(parameters); default: throw new OAuthRuntimeException(format( "String '%s' is not a valid JSON object representation, Expected a ',' or '}", body)); } } } return Collections.unmodifiableMap(parameters); }
From source file:de.wikilab.android.friendica01.TwAjax.java
public Object getJsonResult() { if (!success) return null; try {// w w w .j av a 2 s .c o m JSONTokener jt = new JSONTokener(myResult); return jt.nextValue(); } catch (JSONException ex) { //server returned malformed data return null; } }
From source file:com.dubsar_dictionary.Dubsar.model.Model.java
/** * Fetch data synchronously from the server. */// w w w.j a v a 2s . c o m public void load() { try { /* simple HTTP mock for testing */ mData = getMock(); if (mData == null) mData = fetchData(); JSONTokener tokener = new JSONTokener(mData); parseData(tokener.nextValue()); } /* JSONException, ClientProtocolException and IOException * For now (and perhaps indefinitely), we handle them all alike. */ catch (Exception e) { mError = true; mErrorMessage = e.getMessage(); Log.wtf(TAG, e); } mComplete = true; }