I get this error when sending a get request
this is my code:
* build.gradle *
`apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "ir.supersoft.androidfastnetworking"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'com.library.tangxiaolv:telegramgallery:1.0.3'
}
`
User.java
`public class User {
public int id;
public String first_name;
public String last_name;
public int age;
}
`
MainActivity.java
AndroidNetworking.initialize(getApplicationContext());
`AndroidNetworking.get("http://sekeh.gigfa.com/getUsers.php")
.setTag("test")
.setPriority(Priority.LOW)
.build()
.getAsOkHttpResponseAndObjectList(User.class, new OkHttpResponseAndParsedRequestListener>() {
@Override
public void onResponse(Response okHttpResponse, List
// do anything with response
Log.d("amirhosein", "userList size : " + users.size());
for (User user : users) {
Log.d("amirhosein", "id : " + user.id);
Log.d("amirhosein", "firstname : " + user.first_name);
Log.d("amirhosein", "lastname : " + user.last_name);
Log.d("amirhosein", "age : " + user.age);
}
}
@Override
public void onError(ANError anError) {
Log.e("amirhosein", "error: " + anError.getLocalizedMessage());
}
});
`
i test that in localhost(xampp) but it`s worked!
keep in mind that my androidnetworking version is 1.0.0
because 1.0.1 need to appcompatv7:27.0.2
Do like this
AndroidNetworking.initialize(getApplicationContext());
Gson gson = new GsonBuilder()
.setLenient()
.create();
AndroidNetworking.setParserFactory(new GsonParserFactory(gson));
And also refer this
Also check your response correctly, is it maps to the object correctly?
Use JsonReader.setLen....... is fixed. thank you
but i get this error: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
What is its cause?
my json: http://sekeh.gigfa.com/getUsers.php
Please check the response. Is it matching with the Object?
yes
Provide the dummy response.
Your response is not json. It is text/html so it is unable to parse. Send application/json from the server as the content-type.
it`s worked
the reason is content-type!
Thank you for your prompt answer
Your response is not json. It is text/html so it is unable to parse. Send application/json from the server as the content-type.
very thank you!!!!
Most helpful comment
Your response is not json. It is text/html so it is unable to parse. Send application/json from the server as the content-type.