本文整理汇总了Java中com.eclipsesource.json.JsonValue类的典型用法代码示例。如果您正苦于以下问题:Java JsonValue类的具体用法?Java JsonValue怎么用?Java JsonValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonValue类属于com.eclipsesource.json包,在下文中一共展示了JsonValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getArrayString
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
public static ArrayList<String> getArrayString(JsonArray jsonArray)
{
ArrayList<String> data = new ArrayList<String>();
for (JsonValue jsonValue : jsonArray)
{
data.add(
isNumeric(jsonValue.toString()) ? jsonValue.toString() :
jsonValue.asString()
);
}
return data;
}
示例2: testSingleSubjectKeyConfig
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
/**
* Tests the result of the rest api single subject key GET when
* there is a config.
*/
@Test
public void testSingleSubjectKeyConfig() {
setUpConfigData();
final WebTarget wt = target();
final String response = wt.path("network/configuration/devices").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(1));
JsonValue device1 = result.asObject().get("device1");
Assert.assertThat(device1, notNullValue());
JsonValue basic = device1.asObject().get("basic");
Assert.assertThat(basic, notNullValue());
checkBasicAttributes(basic);
}
示例3: load
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
try {
Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
JsonStage stage = null;
if (entry.getKey().startsWith("block")) {
stage = JsonStage.BLOCK;
} else if (entry.getKey().startsWith("item")) {
stage = JsonStage.ITEM;
} else if (entry.getKey().startsWith("recipe")) {
stage = JsonStage.RECIPE;
} else {
throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
}
Reader reader = entry.getValue().reader();
m.put(stage, Json.parse(reader));
}
}finally {
reader.close();
}
return m;
}
示例4: testSingleSubjectConfig
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
/**
* Tests the result of the rest api single subject GET when
* there is a config.
*/
@Test
public void testSingleSubjectConfig() {
setUpConfigData();
final WebTarget wt = target();
final String response =
wt.path("network/configuration/devices/device1")
.request()
.get(String.class);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(1));
JsonValue basic = result.asObject().get("basic");
Assert.assertThat(basic, notNullValue());
checkBasicAttributes(basic);
}
示例5: testConfigs
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
/**
* Tests the result of the rest api GET when there is a config.
*/
@Test
public void testConfigs() {
setUpConfigData();
final WebTarget wt = target();
final String response = wt.path("network/configuration").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(2));
JsonValue devices = result.get("devices");
Assert.assertThat(devices, notNullValue());
JsonValue device1 = devices.asObject().get("device1");
Assert.assertThat(device1, notNullValue());
JsonValue basic = device1.asObject().get("basic");
Assert.assertThat(basic, notNullValue());
checkBasicAttributes(basic);
}
示例6: getSuccessfulOperationTXID
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
public synchronized String getSuccessfulOperationTXID(String opID)
throws WalletCallException, IOException, InterruptedException
{
String TXID = null;
JsonArray response = this.executeCommandAndGetJsonArray(
"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
JsonObject jsonStatus = response.get(0).asObject();
JsonValue opResultValue = jsonStatus.get("result");
if (opResultValue != null)
{
JsonObject opResult = opResultValue.asObject();
if (opResult.get("txid") != null)
{
TXID = opResult.get("txid").asString();
}
}
return TXID;
}
示例7: executeCommandAndGetJsonValue
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
private JsonValue executeCommandAndGetJsonValue(String command1, String command2, String command3)
throws WalletCallException, IOException, InterruptedException
{
String strResponse = this.executeCommandAndGetSingleStringResponse(command1, command2, command3);
JsonValue response = null;
try
{
response = Json.parse(strResponse);
} catch (ParseException pe)
{
throw new WalletCallException(strResponse + "\n" + pe.getMessage() + "\n", pe);
}
return response;
}
示例8: decomposeJSONValue
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map)
{
if (val.isObject())
{
JsonObject obj = val.asObject();
for (String memberName : obj.names())
{
this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map);
}
} else if (val.isArray())
{
JsonArray arr = val.asArray();
for (int i = 0; i < arr.size(); i++)
{
this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map);
}
} else
{
map.put(name, val.toString());
}
}
示例9: doPost
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
@Override
public ModelAndView doPost(IHTTPSession session) {
JsonValue request = Json.parse(WebServer.getRequestBody(session));
if (!request.isObject()) {
return new BadRequest("expected object");
}
ValidationResult errors = new ValidationResult();
String username = ((JsonObject) request).getString("username", null);
if (username == null || username.trim().length() == 0) {
errors.put("username", "Cannot be empty");
}
if (!errors.isEmpty()) {
LOG.info("unable to save: " + errors);
return new BadRequest(errors);
}
auth.resetPassword(username);
return new Success();
}
示例10: doPost
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
@Override
public ModelAndView doPost(IHTTPSession session) {
JsonValue request = Json.parse(WebServer.getRequestBody(session));
if (!request.isObject()) {
return new BadRequest("expected object");
}
ValidationResult errors = new ValidationResult();
Double lat = WebServer.getDouble(request, "lat");
Double lon = WebServer.getDouble(request, "lng");
if (lat == null) {
errors.put("lat", "Cannot be empty");
}
if (lon == null) {
errors.put("lng", "Cannot be empty");
}
if (!errors.isEmpty()) {
LOG.info("unable to save: " + errors);
return new BadRequest(errors);
}
autoUpdate.setEnabled(WebServer.getBoolean(request, "autoUpdate"));
config.setProperty("locaiton.lat", String.valueOf(lat));
config.setProperty("locaiton.lon", String.valueOf(lon));
config.update();
return new Success();
}
示例11: parse
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
@Override
protected Object parse(Class<?> type, JsonValue value) {
if (type.equals(Map.class)) {
// Construct new map
Map<String, List<AbstractInsnNode>> temp = new HashMap<>();
// For each entry stored in the passes value
value.asObject().forEach(m -> {
// Extract block name and opcode list.
// Put results into map.
String name = m.getName();
JsonArray opcodes = m.getValue().asArray();
List<AbstractInsnNode> opcodeList = new ArrayList<>();
for (JsonValue entry : opcodes.values()) {
opcodeList.add(parse(entry.asObject()));
}
temp.put(name, opcodeList);
});
return temp;
}
return super.parse(type, value);
}
示例12: load
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
JsonStage stage = null;
if (entry.getKey().startsWith("block")) {
stage = JsonStage.BLOCK;
} else if (entry.getKey().startsWith("item")) {
stage = JsonStage.ITEM;
} else if (entry.getKey().startsWith("recipe")) {
stage = JsonStage.RECIPE;
} else {
throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
}
Reader reader = entry.getValue().reader();
try {
m.put(stage, Json.parse(reader));
} finally {
reader.close();
}
}
return m;
}
示例13: fromId
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
/**
* Get strawpoll from its ID
* @param id ID to lookup
* @return Strawpoll Object
* @throws IOException Strawpoll.me is down or denied our API access
*/
public static StrawpollObject fromId(int id) throws IOException {
JsonValue jv = Util.jsonFromUrl(BASE_API + "/" + id);
JsonObject jo = jv.asObject();
String title = jo.getString("title", "title");
boolean multiVote = jo.getBoolean("multi", false);
JsonArray jOptions = jo.get("options").asArray();
String[] options = new String[jOptions.size()];
JsonArray jVotes = jo.get("votes").asArray();
int[] votes = new int[jVotes.size()];
for(int i = 0; i < options.length; i++) {
options[i] = jOptions.get(i).asString();
votes[i] = jVotes.get(i).asInt();
}
return new StrawpollObject(title, multiVote, options, votes);
}
示例14: parseStack
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
public static ItemStack parseStack(JsonValue js) {
if (js.isString()) {
return new ItemStack(getItem(js.asString()));
} else if (js.isObject()) {
JsonObject obj = js.asObject();
JsonValue id = obj.get("id");
if (id == null)
throw new JsonException("No id");
return new ItemStack(getItem(id.asString()), obj.getInt("count", 1), obj.getInt("meta", 0));
} else if (js.isNull()) {
return null;
}
throw new JsonException("Invalid type " + js.toString());
}
示例15: addItem
import com.eclipsesource.json.JsonValue; //导入依赖的package包/类
public static void addItem(JsonObject js) {
if (js.get("tool") != null) {
addItemTool(js);
return;
}
String id = json.getString("id", null);
if (id == null)
throw new JsonException("No item id");
JItem item = new JItem(id);
JsonValue prop;
prop = js.get("texture");
if (prop != null) {
item.textureString = prop.asString();
} else {
item.textureString = id;
}
for (JsonObject.Member member : js) {
switch (member.getName()) {
case "id":
case "texture":
break;
default:
throw new JsonException("Unexpected block member \"" + member.getName() + "\"");
}
}
IDManager.register(item);
}