本文整理匯總了Java中org.json.simple.JSONValue.parseWithException方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONValue.parseWithException方法的具體用法?Java JSONValue.parseWithException怎麽用?Java JSONValue.parseWithException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.simple.JSONValue
的用法示例。
在下文中一共展示了JSONValue.parseWithException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.json.simple.JSONValue; //導入方法依賴的package包/類
@Override
public Object execute(String script) {
StringBuilder sb = new StringBuilder();
// Callback for scripts that want to send some message back to page-inspection.
// We utilize custom alert handling of WebEngine for this purpose.
sb.append("postMessageToNetBeans=function(e) {alert('"); // NOI18N
sb.append(WebBrowserImpl.PAGE_INSPECTION_PREFIX);
sb.append("'+JSON.stringify(e));};\n"); // NOI18N
String quoted = '\"'+JSONValue.escape(script)+'\"';
// We don't want to depend on what is the type of WebBrowser.executeJavaScript()
// for various types of script results => we stringify the result
// (i.e. pass strings only through executeJavaScript()). We decode
// the strigified result then.
sb.append("JSON.stringify({result : eval(").append(quoted).append(")});"); // NOI18N
String wrappedScript = sb.toString();
Object result = browserTab.executeJavaScript(wrappedScript);
String txtResult = result.toString();
try {
JSONObject jsonResult = (JSONObject)JSONValue.parseWithException(txtResult);
return jsonResult.get("result"); // NOI18N
} catch (ParseException ex) {
Logger.getLogger(ScriptExecutorImpl.class.getName()).log(Level.INFO, null, ex);
return ScriptExecutor.ERROR_RESULT;
}
}
示例2: checkForUpdates
import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
* Checks if updates are available.
*/
private void checkForUpdates() {
try {
URL url = new URL("https://api.spiget.org/v2/resources/50955/versions?size=1&sort=-id");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("User-Agent", "EmojiChat Update Checker"); // Sets the user-agent
InputStream inputStream = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
JSONArray value = (JSONArray) JSONValue.parseWithException(reader);
latestVersion = Double.parseDouble(((JSONObject) value.get(value.size() - 1)).get("name").toString());
updateAvailable = currentVersion < latestVersion;
} catch (Exception ignored) { // Something happened, not sure what (possibly no internet connection), so no updates available
updateAvailable = false;
}
}
示例3: executeImpl
import org.json.simple.JSONValue; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public JSONArray executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
ParseException
{
JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());
JSONArray result = new JSONArray();
for (Object o : jsonUsers)
{
String user = (o == null ? null : o.toString());
if (user != null)
{
JSONObject item = new JSONObject();
item.put(user, subscriptionService.follows(userId, user));
result.add(item);
}
}
return result;
}
示例4: executeImpl
import org.json.simple.JSONValue; //導入方法依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
ParseException
{
JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());
for (Object o : jsonUsers)
{
String user = (o == null ? null : o.toString());
if (user != null)
{
subscriptionService.follow(userId, user);
}
}
return null;
}
示例5: executeImpl
import org.json.simple.JSONValue; //導入方法依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
ParseException
{
JSONObject obj = (JSONObject) JSONValue.parseWithException(req.getContent().getContent());
Object setPrivate = obj.get("private");
if (setPrivate != null)
{
if (setPrivate.toString().equalsIgnoreCase("true"))
{
subscriptionService.setSubscriptionListPrivate(userId, true);
} else if (setPrivate.toString().equalsIgnoreCase("false"))
{
subscriptionService.setSubscriptionListPrivate(userId, false);
}
}
return super.executeImpl(userId, req, res);
}
示例6: executeImpl
import org.json.simple.JSONValue; //導入方法依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
ParseException
{
JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());
for (Object o : jsonUsers)
{
String user = (o == null ? null : o.toString());
if (user != null)
{
subscriptionService.unfollow(userId, user);
}
}
return null;
}
示例7: getLastUpdate
import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static Object[] getLastUpdate() {
try {
JSONArray versionsArray = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(String.valueOf(VERSION_URL)), "UTF-8"));
String lastVersion = ((JSONObject) versionsArray.get(versionsArray.size() - 1)).get("name").toString();
if ((Integer.parseInt(lastVersion.replaceAll("\\.","")) > (Integer.parseInt(CommandBlocker.getPlugin(CommandBlocker.class).getDescription().getVersion().replaceAll("\\.",""))))) {
JSONArray updatesArray = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(String.valueOf(DESCRIPTION_URL)), "UTF-8"));
String updateName = ((JSONObject) updatesArray.get(updatesArray.size() - 1)).get("title").toString();
Object[] update = {lastVersion, updateName};
return update;
}
}
catch (Exception e) {
return new String[0];
}
return new String[0];
}
示例8: getLastUpdate
import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static Object[] getLastUpdate() {
try {
JSONArray versionsArray = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(String.valueOf(VERSION_URL)), "UTF-8"));
String lastVersion = ((JSONObject) versionsArray.get(versionsArray.size() - 1)).get("name").toString();
if ((Integer.parseInt(lastVersion.replaceAll("\\.","")) > (Integer.parseInt(TreysDoubleJump.getPlugin(TreysDoubleJump.class).getDescription().getVersion().replaceAll("\\.",""))))) {
JSONArray updatesArray = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(String.valueOf(DESCRIPTION_URL)), "UTF-8"));
String updateName = ((JSONObject) updatesArray.get(updatesArray.size() - 1)).get("title").toString();
Object[] update = {lastVersion, updateName};
return update;
}
}
catch (Exception e) {
return new String[0];
}
return new String[0];
}
示例9: provideJsonPayload
import org.json.simple.JSONValue; //導入方法依賴的package包/類
@Provides
@JsonPayload
@SuppressWarnings("unchecked")
static Map<String, Object> provideJsonPayload(
@Header("Content-Type") MediaType contentType,
@Payload String payload) {
if (!JSON_UTF_8.is(contentType.withCharset(UTF_8))) {
throw new UnsupportedMediaTypeException(
String.format("Expected %s Content-Type", JSON_UTF_8.withoutParameters()));
}
try {
return (Map<String, Object>) JSONValue.parseWithException(payload);
} catch (ParseException e) {
throw new BadRequestException(
"Malformed JSON", new VerifyException("Malformed JSON:\n" + payload, e));
}
}
示例10: getLatestUpdate
import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
* Queries the SpiGet servers and retrieves the latest release information (if current plugin version is outdated.)
*
* @return The updated version number [0], and update title [1] of the resource update
*/
public Object[] getLatestUpdate()
{
try
{
JSONArray versions = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(String.valueOf(VERSION_URL))));
String latestVersion = ((JSONObject) versions.get(versions.size() - 1)).get("name").toString();
int remoteVersionNumber = Integer.parseInt(latestVersion.replaceAll("\\D+", ""));
int localVersionNumber = Integer.parseInt(ChatChannels.get().getDescription().getVersion().replaceAll("\\D+", ""));
System.out.println("[ChatChannels] Checking for updates... Remote version number: " + remoteVersionNumber);
System.out.println("[ChatChannels] Checking for updates... Local version number: " + localVersionNumber);
if (remoteVersionNumber > localVersionNumber)
{
JSONArray updates = (JSONArray) JSONValue.parseWithException(IOUtils.toString(new URL(DESCRIPTION_URL)));
String latestUpdate = ((JSONObject) updates.get(updates.size() - 1)).get("title").toString();
return new Object[]{latestVersion, latestUpdate};
}
else
return null;
}
catch (ParseException | IOException e)
{
e.printStackTrace();
}
return null;
}
示例11: toJSONObject
import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
* Parses the given {@code text} and returns the corresponding JSON object.
*
* @param text text to parse.
* @return JSON object that corresponds to the given text.
* @throws IllegalArgumentException when the given text is not a valid
* representation of a JSON object.
*/
private static JSONObject toJSONObject(String text) throws IllegalArgumentException {
try {
JSONObject json = (JSONObject)JSONValue.parseWithException(text);
return json;
} catch (ParseException ex) {
throw new IllegalArgumentException(text);
}
}
示例12: processStanza
import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
* Handle incoming messages
*/
@SuppressWarnings("unchecked")
@Override
public void processStanza(Stanza packet) {
logger.log(Level.INFO, "Received: " + packet.toXML());
final FcmPacketExtension fcmPacket = (FcmPacketExtension) packet.getExtension(Util.FCM_NAMESPACE);
final String json = fcmPacket.getJson();
try {
final Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parseWithException(json);
final Object messageType = jsonMap.get("message_type");
if (messageType == null) { // normal upstream message
final CcsInMessage inMessage = MessageHelper.createCcsInMessage(jsonMap);
handleUpstreamMessage(inMessage);
return;
}
switch (messageType.toString()) {
case "ack":
handleAckReceipt(jsonMap);
break;
case "nack":
handleNackReceipt(jsonMap);
break;
case "receipt":
handleDeliveryReceipt(jsonMap);
break;
case "control":
handleControlMessage(jsonMap);
break;
default:
logger.log(Level.INFO, "Received unknown FCM message type: " + messageType.toString());
}
} catch (ParseException e) {
logger.log(Level.INFO, "Error parsing JSON: " + json, e.getMessage());
}
}
示例13: unblock
import org.json.simple.JSONValue; //導入方法依賴的package包/類
private void unblock(String selectedVersion, Path sourceFolder) throws HeadlessException {
Path destinationDir = versionsFolder.resolve(selectedVersion + UNBLOCK_SUFFIX);
Path sourceJsonFile = sourceFolder.resolve(selectedVersion + ".json");
Path targetJsonFile = destinationDir.resolve(selectedVersion + UNBLOCK_SUFFIX + ".json");
Path sourceJarFile = sourceFolder.resolve(selectedVersion + ".jar");
Path targetJarFile = destinationDir.resolve(selectedVersion + UNBLOCK_SUFFIX + ".jar");
try {
Files.createDirectory(destinationDir);
Files.copy(sourceJarFile, targetJarFile);
Files.copy(sourceJsonFile, targetJsonFile);
JSONObject json = (JSONObject) JSONValue.parseWithException(new FileReader(targetJsonFile.toFile()));
json.put("id", selectedVersion + UNBLOCK_SUFFIX);
JSONArray libraries = (JSONArray) json.get("libraries");
removeMojangNetty(libraries);
Files.write(targetJsonFile, Arrays.asList(json.toJSONString()), StandardCharsets.UTF_8);
JOptionPane.showMessageDialog(parentComp, "Sucessfully created an unblocked version. \n"
+ "Now restart your launcher and select the version with the suffix -Unblock");
} catch (IOException | ParseException ex) {
Logger.getLogger(MinecraftUnblocker.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(parentComp, "Error " + ex.getMessage());
}
}
示例14: getArray
import org.json.simple.JSONValue; //導入方法依賴的package包/類
private static JSONArray getArray(int spigotResourceID) {JSONArray array = new JSONArray();
try {
array = (JSONArray) JSONValue.parseWithException(connect(spigotResourceID));
} catch(ParseException e) {
e.printStackTrace();
}
return array;
}
示例15: processPacket
import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
* Handles incoming messages
*/
@SuppressWarnings("unchecked")
@Override
public void processPacket(Packet packet) {
logger.log(Level.INFO, "Received: " + packet.toXML());
Message incomingMessage = (Message) packet;
FcmPacketExtension fcmPacket = (FcmPacketExtension) incomingMessage.getExtension(Util.FCM_NAMESPACE);
String json = fcmPacket.getJson();
try {
Map<String, Object> jsonMap = (Map<String, Object>) JSONValue.parseWithException(json);
Object messageType = jsonMap.get("message_type");
if (messageType == null) {
CcsInMessage inMessage = MessageHelper.createCcsInMessage(jsonMap);
handleUpstreamMessage(inMessage); // normal upstream message
return;
}
switch (messageType.toString()) {
case "ack":
handleAckReceipt(jsonMap);
break;
case "nack":
handleNackReceipt(jsonMap);
break;
case "receipt":
handleDeliveryReceipt(jsonMap);
break;
case "control":
handleControlMessage(jsonMap);
break;
default:
logger.log(Level.INFO, "Received unknown FCM message type: " + messageType.toString());
}
} catch (ParseException e) {
logger.log(Level.INFO, "Error parsing JSON: " + json, e.getMessage());
}
}