json 파일을 사용하여 더미 Android Studio 프로젝트의 사용자 데이터를 저장하려고 시도하고 있으며 파일을 읽는 LoginActivity를 테스트하는 동안 오류프롤로그에서 json을 구문 분석 할 수 없습니다.
오류 : 'app : mergeDebugResources'작업에 대한 실행이 실패했습니다.
/Users/james/projects/cwm/app/src/debug/res/values/users.json:1:1: Error: Content is not allowed in prolog.
{
"users": [
{
"name": "James",
"email": "[email protected]",
"address": "addr1",
"password": "password",
"usertype": "USER"
},
{
"name": "Kayla",
"email": "[email protected]",
"address": "addr1",
"password": "password",
"usertype": "MANAGER"
}
]
}
그리고 여기에 내가 오류의 원인이 믿는 LoginActivity의 코드입니다 : 나는 해결책 그러나 대부분의 답변에 유래와 구글을 검색 한
private String loadJSONFromAsset() {
String json = null;
try {
InputStream is = this.getAssets().open("users.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
private void parseJ() {
try {
JSONObject jsonObject = new JSONObject(loadJSONFromAsset());
if(jsonObject != null) {
JSONArray jsonArray = jsonObject.getJSONArray("users");
if(jsonArray != null) {
for(int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = jsonArray.getJSONObject(i);
if(jo != null) {
String name = (String) jo.get("name");
String email = (String) jo.get("email");
String address = (String) jo.get("address");
String password = (String) jo.get("password");
String userType = (String) jo.get("usertype");
User u = new User(name, email, address, password);
u.setUserType(userType);
userList.put(email, u);
a.setMessage(u.toString());
a.show();
}
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
하는 XML과 관련된 또는 JSON 언 마샬링은 내가하고있는 일과 관련이 있다고 생각하지만 잘못 될 수 있습니다. 미리 감사드립니다!
사용자 배열에 닫는 대괄호가 없습니다. 그것이 오류의 원인입니까? – BhalchandraSW
@BhalchandraSW 복사 붙여 넣기에서 놓친 내용이 더 길었습니다. 이것은 더 긴 사용자 목록 중 처음 2 개입니다. 감사합니다. –