当编译器到达onPostExecute并尝试运行执行JSONArray 时
# User-specific stuff:
*/.idea/workspace.xml
*/.idea/tasks.xml
*/.idea/dictionaries
*/.idea/vcs.xml
*/.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
*/.idea/dataSources.ids
*/.idea/dataSources.xml
*/.idea/dataSources.local.xml
*/.idea/sqlDataSources.xml
*/.idea/dynamic.xml
*/.idea/uiDesigner.xml
#MAC OS
.DS_Store
#Intellij
*/target/
*/out/
*.iml
*/.idea/
#Properties
*/*.properties
#IntelliJ
*/out/
*/target/
## File-based project format:
*.iws
## Plugin-specific files:
# mpeltonen/sbt-idea plugin
.idea_modules/
抛出异常:
jsonArray=jsonObject.getJSONArray("server_response");
什么是正确的陈述?
我的代码:
org.json.JSONException:
Value[{"code":"login_true","name":"hhh","email":"hhh"}]
of type org.json.JSONArray cannot be converted to JSONObject".
答案 0 :(得分:1)
假设从服务器返回的JSON
是:
[{"code":"login_true","name":"hhh","email":"hhh"}]
解析上述JSON
:
try {
JSONArray jsonArray = new JSONArray(json);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String code = jsonObject.getString("code");
String name = jsonObject.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}