[英]How to save an array into a PHP database
我嘗試將數組放入數據庫中。 在edittext中,我編寫了例如大蒜,西紅柿,洋蔥,但是當我將數據保存到數據庫並轉到我的php數據庫時,該文本只表示成分,而不是該文本。 如果我手動向數據庫中添加文本(我手動添加了數字而不是成分,但這是同一回事),它看起來不錯,並可以創建好的json文件。 我怎樣才能解決這個問題?
MainActivity.java
String id;
ArrayList<String> ingredients = new ArrayList<String>();
@BindView(R.id.etId) EditText etId;
@BindView(R.id.etIngredients) EditText etIngredients;
id = etId.getText().toString();
ingredients = etIngredients.getText().toString();
Recipes.java
public class Recipes {
String id;
List<String> ingredients;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<String> getIngredients() {
return ingredients;
}
public void setIngredients(List<String> ingredients) {
this.ingredients = ingredients;
}
}
以及如何在列中檢索這些成分?
我用它從json文件返回它,但是它連續返回成分[1,3,4,5,6]
Reipes rec = recipes.get(position);
holder.textViewId.setText(rec.getId());
holder.textViewIngredients.setText(rec.getIngredients().toString());
手動添加前4個食譜,並在android應用中添加配料。
您將不得不更換
ArrayList<String> ingredients = new ArrayList<String>();
通過
String ingredients;
並在您的學習計划中嘗試更改成分的類型
String ingredients;
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.