Hello I would like to know how to connect my Laravel base Web service to My Android Application? Currently im tried with both native and laravel code. and i manage to get the json from native php. but then when I Tried it in Laravel it returns the same json but unable to receive it in Android, the error says something about Doctype
For The Laravel in my Controller
public function jsonview()
{
$data2 =DB::table('item_list')->orderBy('id','desc')->get();
$response = array();
$response["status"] =1;
$response["message"] = "getting data";
$response["data"]=array();
//$response["data"] = $data2;
//or with
foreach ($data2 as $data2) {
$datas = array();
//echo "lol";
$datas["nama_item"] = $data2->nama_item;
$datas["description"] = $data2->description;
$datas["price"] = $data2->harga;
$data = DB::table('users')->where("id","=",$data2->seller)->first();
$datas["seller"] = $data->firstname;
$datas["picture"] = $data2->pic_name;
array_push($response["data"], $datas);
}
//dd(Request::json()->get('data'));
return Response()->json(['data'=>$response["data"]]);
}
Returning Error in Android
it keeps Receiving
Value <!DOCTYPE
here are the full error code
04-21 21:38:06.541 14436-14514/skyvity.belisini E/JSON Parser: Error Parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
My Current Android Which works in native php but yet not receiving in Laravel
package skyvity.belisini.Controller;
import android.util.Log;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import skyvity.belisini.Config.JSONParser;
/**
* Created by Wilztan on 4/20/2016.
*/
public class ItemController {
//Listing Home
public static JSONArray jsonArray= null;
public static ArrayList<String> Item = new ArrayList<String>();
public static ArrayList<String> desc = new ArrayList<String>();
public static ArrayList<String> price = new ArrayList<String>();
public static ArrayList<String> seller = new ArrayList<String>();
public static ArrayList<String> picture = new ArrayList<String>();
public static void list_item(){
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONParser jsonParser= new JSONParser();
JSONObject object jsonParser.request(JSONParser.base_url+"json",params);
try {
if(object.getJSONArray("data")==null){
Log.v("not Failed in here","NULL JSON");
}
jsonArray = object.getJSONArray("data");
Log.v("not Failed in here",jsonArray.toString());
for(int i=0;i<jsonArray.length();i++){
Log.v("notFailed here","Lol");
JSONObject jsonObject = jsonArray.getJSONObject(i);
Item.add(jsonObject.getString("nama_item"));
desc.add(jsonObject.getString("description"));
price.add(jsonObject.getString("price"));
seller.add(jsonObject.getString("seller"));
picture.add(jsonObject.getString("picture"));
}
}catch (JSONException e){
e.printStackTrace();
Log.v("LOL" , e.toString());
}
}}
:D