小编tal*_*ghi的帖子

GSON JsonElement到String

我在将JsonElement转换为字符串时遇到了一些麻烦.我正在使用getAsString()方法调用,但我不断得到不支持的操作异常.我检查了我正在调用的get的输出,看起来是正确的.

这是我的代码,对于糟糕的命名约定抱歉:

JsonParser jp2 = new JsonParser();
JsonObject root2 = jp2.parse(getAllEventsResults.get_Response()).getAsJsonObject();
JsonArray items2 = root2.get("items").getAsJsonArray();

for(int i=0; i<items2.size(); i++){
    JsonObject item = items2.get(i).getAsJsonObject();
    System.out.println(item.get("start").getAsString());}
Run Code Online (Sandbox Code Playgroud)

最奇怪的部分是我在上面用这段代码做同样的事情:

JsonParser jp = new JsonParser();
JsonObject root = jp.parse(getAllCalendarsResults.get_Response()).getAsJsonObject();
JsonArray items = root.get("items").getAsJsonArray();
JsonObject firstItem = items.get(0).getAsJsonObject();
String firstCalId = firstItem.get("id").getAsString();
Run Code Online (Sandbox Code Playgroud)

java json gson

8
推荐指数
1
解决办法
2万
查看次数

Gitignore没有忽略某些project.properties

我正在使用Windows和Mac的github应用程序,我的.gitignore文件有问题.

我试图忽略在我的两台机器之间切换时生成的project.properties文件,但我似乎无法让它工作.

下面是我的.gitignore的副本,它似乎适用于除了project.properties之外的所有东西,以及我在那里的gen/*,但不那么烦人.

我一直在研究这个问题并且没有找到答案,我将不胜感激任何帮助!

# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties
.properties

# Proguard folder generated by Eclipse
`enter code here`proguard/

#Log Files
*.log

project.properties
*.properties
project.properties
Run Code Online (Sandbox Code Playgroud)

git android

7
推荐指数
1
解决办法
7612
查看次数

标签 统计

android ×1

git ×1

gson ×1

java ×1

json ×1