java.lang.IllegalStateException:不是JSON对象:Azure操作上的[]

时间:2017-03-18 16:30:10

标签: android json azure-mobile-services azure-android-sdk gson

我正在使用 Azure移动应用 在注册期间插入我的新用户

然后它会抛出一条带有消息的异常:  java.lang.IllegalStateException:不是JSON对象:[]

(我在Users表中没有实体

我的代码:

public static void registerUserToTheDataBase(final User user){
    AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            try {
                UserManager.user = mUserManager.insert(user).get();
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }
    };
    AsyncTaskController.runAsyncTask(asyncTask);
}

我已经检查了所有数据库属性的名称是否正确

这是我的用户对象

public class User implements Serializable {
@com.google.gson.annotations.SerializedName("id")
private String id;
@com.google.gson.annotations.SerializedName("name")
private String name;
@com.google.gson.annotations.SerializedName("live")
private String live;
@com.google.gson.annotations.SerializedName("age")
private int age;
@com.google.gson.annotations.SerializedName("password")
private String password;
@com.google.gson.annotations.SerializedName("account")
private String account;
@com.google.gson.annotations.SerializedName("phone")
private String phone;
@com.google.gson.annotations.SerializedName("email")
private String email;
@com.google.gson.annotations.SerializedName("imageUrl")
private String imageUrl;

@com.google.gson.annotations.SerializedName("productsHistoryRecord")
private List<ProductImp> productsHistoryRecord;
@com.google.gson.annotations.SerializedName("productsSales")
private List<ProductImp> productsSales;
@com.google.gson.annotations.SerializedName("productsInCart")
private List<ProductImp> productsInCart;
@com.google.gson.annotations.SerializedName("mails")
private List<Mail> mails;


public String getImageUrl() {
    return imageUrl;
}

public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
}

public String getId() {
    return id;
}

public String getName() {
    return name;
}

public int getAge() {
    return age;
}

public String getAccount() {
    return account;
}

public String getLive() {
    return live;
}

public String getPassword() {
    return password;
}

public String getPhone() {
    return phone;
}

public void setName(String name) {
    this.name = name;
}

public void setAccount(String account) {
    this.account = account;
}

public void setAge(int age) {
    this.age = age;
}

public void setLive(String live) {
    this.live = live;
}

public void setPassword(String password) {
    this.password = password;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public void setId(String id) {
    this.id = id;
}

public void setEmail(String email) {
    this.email = email;
}

public String getEmail() {
    return email;
}

public List<Mail> getMails() {
    return mails;
}

public void setMails(List<Mail> mails) {
    this.mails = mails;
}

public List<ProductImp> getProductsHistoryRecord() {
    return productsHistoryRecord;
}

public void setProductsHistoryRecord(List<ProductImp> productsHistoryRecord) {
    this.productsHistoryRecord = productsHistoryRecord;
}

public List<ProductImp> getProductsInCart() {
    return productsInCart;
}

public void setProductsInCart(List<ProductImp> productsInCart) {
    this.productsInCart = productsInCart;
}

public List<ProductImp> getProductsSales() {
    return productsSales;
}

public void setProductsSales(List<ProductImp> productsSales) {
    this.productsSales = productsSales;
}

@Override
public String toString() {
    return "user information :" + name + "," + age + "," + live + "," + phone + "," + account + "," + password
      +   ","   + productsHistoryRecord + "," + productsInCart + "," +  productsSales ;
}

}

用户和产品之间有三种关系

以及我实例化MobileServerClient

的方法
public static void initiate(Context context) throws MalformedURLException {
    mClient = new MobileServiceClient(LINK,context).withFilter(new ProgressFilter());
    mClient.setAndroidHttpClientFactory(new OkHttpClientFactory() {
        @Override
        public OkHttpClient createOkHttpClient() {
            OkHttpClient client = new OkHttpClient();
            client.setReadTimeout(20, TimeUnit.SECONDS);
            client.setWriteTimeout(20, TimeUnit.SECONDS);
            return client;
        }
    });
    initiateTables();
}

public static void initiateTables(){
    mUserManager = mClient.getTable("User",User.class);
    mProduct = mClient.getTable("Product",ProductImp.class);
    mMail = mClient.getTable("Mail",Mail.class);
    mLockerImp = mClient.getTable("Locker",LockerImp.class);
    mCart = mClient.getTable("Cart",CartList.class);
}

这是User表的后端数据库模式 我在第一个单词中将所有属性更改为大写 否则会发生错误。

enter image description here

非常感谢。

1 个答案:

答案 0 :(得分:2)

尝试将网址http修改为https