整理错误
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project '项目名' is using version 1.1.51.
解决方式 在最外层build.gradle 中修改
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
}
}
Android app\build\intermediates\res\merged\debug\values-vXX\values-vXX.xml
解决方法
app build.gradle中 compileSdkVersion buildToolsVersion targetSdkVersion一致
Anderoid List转json字符串
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
JSONObject tmpObj = null;
int count = anwerList.size();
for (int i = 0; i < count; i++) {
tmpObj = new JSONObject();
try {
tmpObj.put("QuestionType", anwerList.get(i).get("type"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
tmpObj.put("CorrectAnswer", anwerList.get(i).get("answer"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
tmpObj.put("QuestionNum",Integer.parseInt(i+1+""));
} catch (JSONException e) {
e.printStackTrace();
}
jsonArray.put(tmpObj);
tmpObj = null;
}
String personInfos = jsonArray.toString(); // 将JSONArray转换得到String
4.Android json字符串的读取
JsonArray returnData = new JsonParser().parse(dataStr).getAsJsonArray();
for (int i = 0; i < returnData.size(); i++) {
String type = returnData.get(i).getAsJsonObject().get("QuestionType").getAsString();
String answer = returnData.get(i).getAsJsonObject().get("CorrectAnswer").getAsString();
Dictionary<String, String> hashTable = new Hashtable<String, String>();
hashTable.put("type", type);
hashTable.put("answer", answer);
hashTable.put("num", i + 1 + "");
}
网友评论