use of org.json.simple.parser.JSONParser in project jackrabbit-oak by apache.
the class DocumentMKBranchTest method movesInBranch.
@Test
public void movesInBranch() throws Exception {
String branchRev = mk.branch(null);
branchRev = mk.commit("/", "+\"a\":{}", branchRev, null);
branchRev = mk.commit("/a", "^\"foo\":1", branchRev, null);
branchRev = mk.commit("/", ">\"a\" : \"b\"", branchRev, null);
branchRev = mk.commit("/", ">\"b\" : \"a\"", branchRev, null);
mk.merge(branchRev, null);
String json = mk.getNodes("/a", null, 0, 0, -1, null);
JSONParser parser = new JSONParser();
JSONObject obj = (JSONObject) parser.parse(json);
assertTrue(obj.containsKey("foo"));
}
use of org.json.simple.parser.JSONParser in project Glowstone by GlowstoneMC.
the class LootingManager method register.
private static void register(EntityType type, String location) throws Exception {
try {
InputStream in = LootingManager.class.getClassLoader().getResourceAsStream(location);
if (in == null) {
GlowServer.logger.warning("Could not find default entity loot table '" + location + "' on classpath");
return;
}
JSONObject json = (JSONObject) new JSONParser().parse(new InputStreamReader(in));
entities.put(type, new EntityLootTable(json));
} catch (Exception e) {
Exception ex = new Exception("Failed to load loot table '" + location + "': " + e.getClass().getName() + " (" + e.getMessage() + ")");
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
use of org.json.simple.parser.JSONParser in project Glowstone by GlowstoneMC.
the class PlayerStatisticIoService method readStats.
/**
* Reads the stats of a player from its statistics file and writes the values to the StatisticMap.
*
* @param player the player to read the statistics from
*/
public void readStats(GlowPlayer player) {
File statsFile = getPlayerFile(player.getUniqueId());
player.getStatisticMap().getValues().clear();
if (statsFile.exists()) {
try {
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(new FileReader(statsFile));
for (Object obj : json.entrySet()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj;
Long longValue = null;
if (entry.getValue() instanceof Long) {
longValue = (Long) entry.getValue();
} else if (entry.getValue() instanceof JSONObject) {
JSONObject object = (JSONObject) entry.getValue();
if (object.containsKey("value")) {
longValue = (Long) object.get("value");
}
} else {
GlowServer.logger.warning("Unknown statistic type for '" + entry.getKey() + "': " + entry.getValue() + " (" + entry.getValue().getClass().getSimpleName() + ")");
}
if (longValue != null) {
player.getStatisticMap().getValues().put(entry.getKey(), longValue.intValue());
}
}
} catch (ParseException | IOException e) {
e.printStackTrace();
}
}
}
use of org.json.simple.parser.JSONParser in project Gargoyle by callakrsos.
the class JsonTest method jsonTest.
@Test
public void jsonTest() throws ParseException {
JSONArray jsonArray = new JSONArray();
{
JSONObject jsonObject = new JSONObject();
jsonObject.put("svn.url", "http://sample.net");
jsonObject.put("svn.userId", "userId");
jsonObject.put("svn.userPass", "userPass");
jsonArray.add(jsonObject);
}
{
JSONObject jsonObject = new JSONObject();
jsonObject.put("svn.url", "http://sample.ssdsds.net");
jsonObject.put("svn.userId", "userId");
jsonObject.put("svn.userPass", "userPass");
jsonArray.add(jsonObject);
}
System.out.println(jsonArray.toJSONString());
// JSONArray jsonArray2 = new JSONArray();
JSONArray parse = (JSONArray) new JSONParser().parse(jsonArray.toJSONString());
parse.forEach(System.out::println);
}
use of org.json.simple.parser.JSONParser in project cogcomp-nlp by CogComp.
the class QueryMQL method getResponse.
public JSONObject getResponse(String mqlQuery) throws IOException, ParseException {
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
JSONParser parser = new JSONParser();
GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
url.put("query", mqlQuery);
url.put("key", apikey);
logger.debug("Querying Freebase QUERY URL: " + url.toString());
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse httpResponse;
try {
httpResponse = request.execute();
} catch (HttpResponseException e) {
e.printStackTrace();
int statusCode = e.getStatusCode();
logger.error("StatusCode " + statusCode);
logger.error("Query URL was " + url.toString());
logger.error("Query was " + mqlQuery);
if (// max limit reached for a day
statusCode == 403) {
System.exit(-1);
}
return null;
} catch (SocketTimeoutException e) {
e.printStackTrace();
return null;
}
JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
return response;
}
Aggregations