本文整理汇总了Java中com.google.gson.JsonObject.getAsJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getAsJsonObject方法的具体用法?Java JsonObject.getAsJsonObject怎么用?Java JsonObject.getAsJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getAsJsonObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public VKApiComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
VKApiComment dto = new VKApiComment();
dto.id = optInt(root, "id");
dto.from_id = optInt(root, "from_id");
if(dto.from_id == 0){
dto.from_id = optInt(root, "owner_id");
}
dto.date = optLong(root, "date");
dto.text = optString(root, "text");
dto.reply_to_user = optInt(root, "reply_to_user");
dto.reply_to_comment = optInt(root, "reply_to_comment");
if(root.has("attachments")){
dto.attachments = context.deserialize(root.get("attachments"), VkApiAttachments.class);
}
if(root.has("likes")){
JsonObject likesRoot = root.getAsJsonObject("likes");
dto.likes = optInt(likesRoot, "count");
dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
dto.can_like = optIntAsBoolean(likesRoot, "can_like");
}
dto.can_edit = optIntAsBoolean(root, "can_edit");
return dto;
}
示例2: Configuration
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* Creates a new configuration with the given root element
*
* @param root The root object
*
* @throws UndefinedTokenException If the bot token is undefined
* @throws UnknownHostException If the hostname could not be resolved
*/
Configuration(JsonObject root) throws UndefinedTokenException, UnknownHostException {
final JsonElement tokenE = root.get("token");
if (tokenE.isJsonNull()) throw new UndefinedTokenException();
else token = tokenE.getAsString();
final JsonElement adminE = root.get("admin");
admin = adminE.isJsonNull() ? null : adminE.getAsString();
debugLevel = root.get("debugLevel").getAsByte();
JsonObject db = root.getAsJsonObject("db");
databaseName = db.get("name").getAsString();
JsonObject socket = root.getAsJsonObject("socket");
socketHost = InetAddress.getByName(socket.get("host").getAsString());
socketPort = socket.get("port").getAsShort();
}
示例3: getTextures
import com.google.gson.JsonObject; //导入方法依赖的package包/类
private Map<String, String> getTextures(JsonObject p_178329_1_)
{
Map<String, String> map = Maps.<String, String>newHashMap();
if (p_178329_1_.has("textures"))
{
JsonObject jsonobject = p_178329_1_.getAsJsonObject("textures");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(entry.getKey(), ((JsonElement)entry.getValue()).getAsString());
}
}
return map;
}
示例4: parseLocation
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public LocationDTO parseLocation(String result){
JsonParser parser = new JsonParser();
JsonObject json = (JsonObject) parser.parse(result);
JsonElement jsonCode = json.get("status");
String code = jsonCode.getAsString();
if(! (code.equals("OK"))){
return null;
}
JsonArray jsonArray = json.getAsJsonArray("results");
JsonElement elm = jsonArray.get(0);
JsonObject obj = elm.getAsJsonObject();
JsonObject ob2 = obj.getAsJsonObject("geometry");
JsonObject obj3 = ob2.getAsJsonObject("location");
String jsonString = obj3.toString();
Gson gson = new GsonBuilder().create();
LocationDTO loc = gson.fromJson(jsonString, LocationDTO.class);
return loc;
}
示例5: set
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public void set(String key, Object value)
{
if (key.contains("."))
{
try
{
String[] split = key.split("\\.");
JsonObject object = config;
for (int i = 0; i < split.length - 1; i++)
{
String str = split[i];
if (!object.has(str))
{
object.add(str, new JsonObject());
}
object = object.getAsJsonObject(str);
}
object.add(split[split.length - 1], gson.toJsonTree(value));
}
catch (JsonParseException ignored)
{
}
}
else
{
config.add(key, gson.toJsonTree(value));
}
if (autoSave)
{
save();
}
}
示例6: generatePlaylist
import com.google.gson.JsonObject; //导入方法依赖的package包/类
static String generatePlaylist(String contentJson, JsonObject channelsJson, String host, int port) {
JsonArray neterraContentArray = new JsonParser().parse(contentJson).getAsJsonObject()
.get("tv_choice_result").getAsJsonArray();
StringBuilder m3u8 = new StringBuilder("#EXTM3U\n");
for (int i = 0; i < neterraContentArray.size(); i++) {
JsonObject channel = neterraContentArray.get(i).getAsJsonArray().get(0).getAsJsonObject();
String chanId = channel.get("issues_id").getAsString();
String chanName = channel.get("issues_name").getAsString();
String tvgId = "";
String tvgName = "";
String group = "";
String logo = "";
JsonObject definedChannel = channelsJson.getAsJsonObject(chanId);
if (definedChannel != null) {
chanName = definedChannel.get("name").getAsString();
tvgId = definedChannel.get("tvg-id").getAsString();
tvgName = definedChannel.get("tvg-name").getAsString();
group = definedChannel.get("group").getAsString();
logo = definedChannel.get("logo").getAsString();
}
String encodedChanName = null;
try {
encodedChanName = URLEncoder.encode(chanName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
m3u8.append(String.format("#EXTINF:-1 tvg-id=\"%s\" tvg-name=\"%s\" tvg-logo=\"%s\" " +
"group-title=\"%s\",%s\nhttp://%s:%s/playlist.m3u8?ch=%s&name=%s\n",
tvgId, tvgName, logo, group, chanName, host, port, chanId, encodedChanName));
}
return m3u8.toString();
}
示例7: getRecommendedLocation
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public String getRecommendedLocation()
{
try
{
String freeGeoIP = Util.getWebResponse("https://www.creeperhost.net/json/datacentre/closest");
JsonObject jObject = new JsonParser().parse(freeGeoIP).getAsJsonObject();
jObject = jObject.getAsJsonObject("datacentre");
return jObject.getAsJsonPrimitive("name").getAsString();
}
catch (Throwable t)
{
}
return ""; // default
}
示例8: extensionKeyFromExtraExtensionKey
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static String extensionKeyFromExtraExtensionKey(JsonElement jsonElement) {
JsonObject asJsonObject = jsonElement.getAsJsonObject();
if (!asJsonObject.has("extra")) {
return null;
}
JsonObject extra = asJsonObject.get("extra").getAsJsonObject();
if (!extra.has("typo3/cms")) {
return null;
}
JsonObject typo3Extras = extra.getAsJsonObject("typo3/cms");
if (!typo3Extras.has("extension-key")) {
return null;
}
return typo3Extras.getAsJsonPrimitive("extension-key").getAsString();
}
示例9: SaveField
import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
* Create an editable or togglable SaveField restricted to the specs provided
*
* @param json the JsonObject for the SaveField to listen
* @param jpath the path of the JSON, which contains two string values
* @param title the title of the field's JLabel
* @param type the DataType to which the SaveField is restricted
*/
public SaveField(JsonObject json, String[] jpath, String title, DataType type){
this.json = json.getAsJsonObject(jpath[0]);
this.jpath = new String[jpath.length-1];
for( int i = 0; i < this.jpath.length; i++)
this.jpath[i] = jpath[i+1];
this.setLayout(new BorderLayout());
this.add(new JLabel(title), BorderLayout.PAGE_START);
switch(type){
case INTEGER: initIntegerField(); break;
case STRING: initStringField(); break;
case BOOL: initBoolField(); break;
case SPELL: initSpellField(); break;
case DASH: initDashField(); break;
case DREAMNAIL: initDreamField(); break;
}
}
示例10: SkriptServerResponse
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public SkriptServerResponse(JsonElement element) {
JsonObject json = element.getAsJsonObject();
address = json.get("address").getAsString();
online = json.get("online").getAsBoolean();
if (online) {
latency = json.get("latency").getAsFloat();
JsonObject playersJson = json.getAsJsonObject("players");
onlinePlayers = playersJson.get("online").getAsInt();
maxPlayers = playersJson.get("max").getAsInt();
playersList = new ArrayList<>();
JsonArray playersListJson = playersJson.getAsJsonArray("list");
for (JsonElement player : playersListJson) {
playersList.add(player.getAsString());
}
JsonObject versionJson = json.getAsJsonObject("version");
version = versionJson.get("name").getAsString();
protocol = versionJson.get("protocol").getAsInt();
description = json.get("description").getAsString();
favicon = json.get("favicon").getAsString();
} else {
latency = null;
onlinePlayers = null;
maxPlayers = null;
playersList = null;
version = null;
protocol = null;
description = null;
favicon = null;
}
}
示例11: createOrder
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public String createOrder(final Order order)
{
try
{
String response = Util.postWebResponse("https://www.creeperhost.net/json/order/" + order.clientID + "/" + order.productID + "/" + order.serverLocation, new HashMap<String, String>()
{{
put("name", order.name);
put("swid", Config.getInstance().getVersion());
if (order.pregen)
put("pregen", String.valueOf(Config.getInstance().getPregenDiameter()));
}});
if (response.equals("error"))
{
}
else
{
JsonElement jElement = new JsonParser().parse(response);
JsonObject jObject = jElement.getAsJsonObject();
if (jObject.getAsJsonPrimitive("status").getAsString().equals("success"))
{
jObject = jObject.getAsJsonObject("more");
return "success:" + jObject.getAsJsonPrimitive("invoiceid").getAsString() + ":" + jObject.getAsJsonPrimitive("orderid").getAsString();
}
else
{
return jObject.getAsJsonPrimitive("message").getAsString();
}
}
return "Unknown error";
}
catch (Throwable t)
{
CreeperHost.logger.error("Unable to create order");
return "Unknown error";
}
}
示例12: updateField
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static boolean updateField(JsonElement json, String field, String value) {
if (json == null || !(json instanceof JsonObject)) {
return false;
}
JsonObject jsonObject = (JsonObject) json;
// We reached the leaf, update the field if it exists
if (!field.contains(".")) {
JsonElement element = jsonObject.get(field);
if (element == null) {
return false;
}
if (element.isJsonPrimitive()) {
jsonObject.addProperty(field, value);
return true;
} else {
return false;
}
}
int i = field.indexOf('.');
JsonObject child = jsonObject.getAsJsonObject(field.substring(0, i));
String childField = field.substring(i + 1, field.length());
return updateField(child, childField, value);
}
示例13: deserialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public FontMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
float[] afloat = new float[256];
float[] afloat1 = new float[256];
float[] afloat2 = new float[256];
float f = 1.0F;
float f1 = 0.0F;
float f2 = 0.0F;
if (jsonobject.has("characters"))
{
if (!jsonobject.get("characters").isJsonObject())
{
throw new JsonParseException("Invalid font->characters: expected object, was " + jsonobject.get("characters"));
}
JsonObject jsonobject1 = jsonobject.getAsJsonObject("characters");
if (jsonobject1.has("default"))
{
if (!jsonobject1.get("default").isJsonObject())
{
throw new JsonParseException("Invalid font->characters->default: expected object, was " + jsonobject1.get("default"));
}
JsonObject jsonobject2 = jsonobject1.getAsJsonObject("default");
f = JsonUtils.getFloat(jsonobject2, "width", f);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f, "Invalid default width");
f1 = JsonUtils.getFloat(jsonobject2, "spacing", f1);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f1, "Invalid default spacing");
f2 = JsonUtils.getFloat(jsonobject2, "left", f1);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f2, "Invalid default left");
}
for (int i = 0; i < 256; ++i)
{
JsonElement jsonelement = jsonobject1.get(Integer.toString(i));
float f3 = f;
float f4 = f1;
float f5 = f2;
if (jsonelement != null)
{
JsonObject jsonobject3 = JsonUtils.getJsonObject(jsonelement, "characters[" + i + "]");
f3 = JsonUtils.getFloat(jsonobject3, "width", f);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f3, "Invalid width");
f4 = JsonUtils.getFloat(jsonobject3, "spacing", f1);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f4, "Invalid spacing");
f5 = JsonUtils.getFloat(jsonobject3, "left", f2);
Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f5, "Invalid left");
}
afloat[i] = f3;
afloat1[i] = f4;
afloat2[i] = f5;
}
}
return new FontMetadataSection(afloat, afloat2, afloat1);
}
示例14: deserialize
import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public VKApiVideo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
VKApiVideo dto = new VKApiVideo();
dto.id = optInt(root, "id");
dto.owner_id = optInt(root, "owner_id");
dto.title = optString(root, "title");
dto.description = optString(root, "description");
dto.duration = optInt(root, "duration");
dto.link = optString(root, "link");
dto.date = optLong(root, "date");
dto.adding_date = optLong(root, "adding_date");
dto.views = optInt(root, "views");
JsonElement commentJson = root.get("comments");
if(nonNull(commentJson)){
if(commentJson.isJsonObject()){
//for example, newsfeed.getComment
dto.comments = context.deserialize(commentJson, CommentsDto.class);
} else {
// video.get
dto.comments = new CommentsDto();
dto.comments.count = commentJson.getAsInt();
}
}
dto.player = optString(root, "player");
dto.access_key = optString(root, "access_key");
dto.album_id = optInt(root, "album_id");
if(root.has("likes")){
JsonObject likesRoot = root.getAsJsonObject("likes");
dto.likes = optInt(likesRoot, "count");
dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
}
dto.can_comment = optIntAsBoolean(root, "can_comment");
dto.can_repost = optIntAsBoolean(root, "can_repost");
dto.repeat = optIntAsBoolean(root, "repeat");
if(root.has("privacy_view")){
dto.privacy_view = context.deserialize(root.get("privacy_view"), VkApiPrivacy.class);
}
if(root.has("privacy_comment")){
dto.privacy_comment = context.deserialize(root.get("privacy_comment"), VkApiPrivacy.class);
}
if(root.has("files")){
JsonObject filesRoot = root.getAsJsonObject("files");
dto.mp4_240 = optString(filesRoot, "mp4_240");
dto.mp4_360 = optString(filesRoot, "mp4_360");
dto.mp4_480 = optString(filesRoot, "mp4_480");
dto.mp4_720 = optString(filesRoot, "mp4_720");
dto.mp4_1080 = optString(filesRoot, "mp4_1080");
dto.external = optString(filesRoot, "external");
}
dto.photo_130 = optString(root, "photo_130");
dto.photo_320 = optString(root, "photo_320");
dto.photo_800 = optString(root, "photo_800");
dto.platform = optString(root, "platform");
dto.can_edit = optIntAsBoolean(root, "can_edit");
dto.can_add = optIntAsBoolean(root, "can_add");
return dto;
}
示例15: getOrgId
import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static String getOrgId(String token, String orgName, String environment, Boolean debug_mode) {
CloseableHttpClient httpClient = HttpClients.createDefault();
String organizations_url = chooseOrganizationsUrl(environment);
if(debug_mode){
LOGGER.info("GET ORG_GUID URL:" + organizations_url + orgName);
}
try {
HttpGet httpGet = new HttpGet(organizations_url + URLEncoder.encode(orgName, "UTF-8").replaceAll("\\+", "%20"));
httpGet = addProxyInformation(httpGet);
httpGet.setHeader("Authorization", token);
CloseableHttpResponse response = null;
response = httpClient.execute(httpGet);
String resStr = EntityUtils.toString(response.getEntity());
if(debug_mode){
LOGGER.info("RESPONSE FROM ORGANIZATIONS API:" + response.getStatusLine().toString());
}
if (response.getStatusLine().toString().contains("200")) {
// get 200 response
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(resStr);
JsonObject obj = element.getAsJsonObject();
JsonArray resources = obj.getAsJsonArray("resources");
if(resources.size() > 0) {
JsonObject resource = resources.get(0).getAsJsonObject();
JsonObject metadata = resource.getAsJsonObject("metadata");
if(debug_mode){
LOGGER.info("ORG_ID:" + String.valueOf(metadata.get("guid")).replaceAll("\"", ""));
}
return String.valueOf(metadata.get("guid")).replaceAll("\"", "");
}
else {
if(debug_mode){
LOGGER.info("RETURNED NO ORGANIZATIONS.");
}
return null;
}
} else {
if(debug_mode){
LOGGER.info("RETURNED STATUS CODE OTHER THAN 200. RESPONSE: " + response.getStatusLine().toString());
}
return null;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}