How to store jsonarray to arraylist string? please any help is much appreciated. this is my jsonarray
{
"ids":[
{
"noid":"2"
},
{
"noid":"3"
}
],
"success":1
}
I want to store the values of identity "noid" in arraylist. here is my code in android.
protected String doInBackground(String... args) {
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("qid", qsid));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jParser.makeHttpRequest(
main_url, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
success = json.getInt("success");
if (success == 1) {
// successfully received product details
JSONArray idSet = json
.getJSONArray("ids"); // JSON Array
for(int i = 0; i < idSet.length(); i++) {
JSONObject outputId = idSet.getJSONObject(i);
arrayList.add(outputId.getString("noid").toString());
}
}else{
Toast.makeText(getApplicationContext(), json.getString("result"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
and here is my php file.
<?php
require_once 'mobile_question_query.php';
$j = array();
if(isset($_GET["qid"])){
$id = $_GET['qid'];
$fetchallqObject = new Questions();
if(!empty($id)){
$json_array = $fetchallqObject->fetchAllQuestionsID($id);
echo json_encode($json_array);
}else{
$j['result'] = "No id!";
echo json_encode($j);
}
}else{
echo "no id found";
}
?>
if i check the array if arraylist is empty, it return always true.