это код JSON и HttpURLConnection получить данные из JSONОшибка org.json.JSONException вставки данных
protected Void doInBackground(Void...params){
InputStream is=null;
String result="";
String urlDate="http://pangkortourism.ga/fyp/player.php";
BufferedReader reader=null;
try{
URL urlp=new URL(urlDate);
try {
HttpURLConnection c = (HttpURLConnection) urlp.openConnection();
c.setRequestMethod("GET");
c.setReadTimeout(10000);
c.connect();
reader = new BufferedReader(new InputStreamReader(c.getInputStream(), "UTF-8"));
StringBuilder buf = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
buf.append(line);
}
result = buf.toString();
}
finally {
if (reader != null) {
reader.close();
}
}
} catch (IOException e) {
Log.e("MalformedURLException", "MalformedURLException " + e.toString());
}
//parse json data
try{
// Remove unexpected characters that might be added to beginning of the string
result=result.substring(result.indexOf("["));
JSONArray jArray =new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Product p=new Product();
p.setid(json_data.getString("id"));
p.setitem(json_data.getInt("item"));
records.add(p);
}
}
catch(Exception e){
Log.e("ERROR", "Error pasting data "+e.toString());
}
return null;
}
данные базы данных MySQL
JSON код
[
{"0":"1","id":"1","1":"pizza","item":"pizza"},
{"0":"2","id":"2","1":"burger","item":"burger"}
]
Ошибка в Android Studio
04-07 11:58:12.527 23232-23303/com.khor.newtry6 E/ERROR: Error pasting data org.json.JSONException: Value pizza at item of type java.lang.String cannot be converted to int 04-07 11:58:12.542 23232-23232/com.khor.newtry6 E/size: 0
json_data.getInt ("item")); item не numeric – user993553
вопрос был отвечен мной первым и остальным скопировал пасту: P – KOTIOS