当前位置: 首页>>代码示例>>Java>>正文


Java JSONValue.parseWithException方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ScriptExecutorImpl.java

示例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;
	}
}
 
开发者ID:RadBuilder,项目名称:EmojiChat,代码行数:23,代码来源:EmojiChatUpdateChecker.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:22,代码来源:SubscriptionServiceFollowsPost.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:17,代码来源:SubscriptionServiceFollowPost.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:21,代码来源:SubscriptionServicePrivateListPut.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:17,代码来源:SubscriptionServiceUnfollowPost.java

示例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];
  }
 
开发者ID:TreyRuffy,项目名称:CommandBlocker,代码行数:19,代码来源:UpdateChecker.java

示例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];
  }
 
开发者ID:TreyRuffy,项目名称:TreysDoubleJump,代码行数:19,代码来源:UpdateChecker.java

示例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));
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:RequestModule.java

示例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;
}
 
开发者ID:codenameflip,项目名称:ChatChannels,代码行数:37,代码来源:UpdateHandler.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SourceMap.java

示例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());
	}

}
 
开发者ID:carlosCharz,项目名称:fcmxmppserverv2,代码行数:41,代码来源:CcsClient.java

示例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());
    }
}
 
开发者ID:games647,项目名称:MinecraftUnblocker,代码行数:28,代码来源:UnblockButtonListener.java

示例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;
    }
 
开发者ID:x9nico,项目名称:ViaCheckConnection,代码行数:11,代码来源:BungeeUpdater.java

示例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());
	}

}
 
开发者ID:carlosCharz,项目名称:fcmxmppserver,代码行数:42,代码来源:CcsClient.java


注:本文中的org.json.simple.JSONValue.parseWithException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。