/** * Parses the supplied JSON string and returns a list of comments. * * @param json * @return * @throws JSONException */ static List<Comment> parseComments(String json) throws JSONException { List<Comment> comments = new ArrayList<Comment>(); /* * null * Array containing arrays of comments * numberOfComments */ JSONArray jsonComments = new JSONObject(json).getJSONObject("result").getJSONArray("1"); int count = jsonComments.length(); for (int i = 0; i < count; i++) { Comment comment = new Comment(); JSONObject jsonComment = jsonComments.getJSONObject(i); // TODO These examples are out of date and need updating /* * null * "gaia:17919762185957048423:1:vm:11887109942373535891", -- ID? * "REVIEWERS_NAME", * "1343652956570", -- DATE? * RATING, * null * "COMMENT", * null, * "VERSION_NAME", * [ null, * "DEVICE_CODE_NAME", * "DEVICE_MANFACTURER", * "DEVICE_MODEL" * ], * "LOCALE", * null, * 0 */ // Example with developer reply /* * [ * null, * "gaia:12824185113034449316:1:vm:18363775304595766012", * "Micka�l", * "1350333837326", * 1, * "", * "Nul\tNul!! N'arrive pas a scanner le moindre code barre!", * 73, * "3.2.5", * [ * null, * "X10i", * "SEMC", * "Xperia X10" * ], * "fr_FR", * [ * null, * "Prixing fonctionne pourtant bien sur Xperia X10. Essayez de prendre un minimum de recul, au moins 20 � 30cm, �vitez les ombres et les reflets. N'h�sitez pas � nous �crire sur [email protected] pour une assistance personnalis�e." * , * null, * "1350393460968" * ], * 1 * ] */ String user = jsonComment.optString("2"); if (user != null && !"".equals(user) && !"null".equals(user)) { comment.setUser(user); } comment.setDate(parseDate(jsonComment.getLong("3"))); comment.setRating(jsonComment.getInt("4")); String version = jsonComment.optString("7"); if (version != null && !"".equals(version) && !version.equals("null")) { comment.setAppVersion(version); } comment.setText(jsonComment.optJSONObject("5").getString("3")); JSONObject jsonDevice = jsonComment.optJSONObject("8"); if (jsonDevice != null) { String device = jsonDevice.optString("3"); JSONArray extraInfo = jsonDevice.optJSONArray("2"); if (extraInfo != null) { device += " " + extraInfo.optString(0); } comment.setDevice(device.trim()); } JSONArray jsonReply = jsonComment.optJSONArray("11"); if (jsonReply != null) { Comment reply = new Comment(true); reply.setText(jsonReply.getString(1)); reply.setReplyDate(parseDate(jsonReply.getLong(3))); reply.setDate(comment.getDate()); comment.setReply(reply); } comments.add(comment); } return comments; }