PHP:读取json arraylist并在mysql中保存数据? [英] php : reading json arraylist and saving data in mysql?
问题描述
我想将android中的arraylist
读入php
以便存储在database
中,但是我无法找到确切的代码.有人可以指导我解决这个问题的方向吗?
I want to read arraylist
from android into php
in order to store in database
, but I'm not able to find exact code for it. Can anybody guide me in the direction to solve this problem ?
这是我用于创建arraylist
private void loadCart()
{
productList.clear();
Cursor cursor = dbHelper.getCarProducts();
cursor.moveToFirst();
do {
CartProduct cartProduct = new CartProduct();
cartProduct.setProductName("Name: "+cursor.getString(cursor.getColumnIndex("_Name")));
cartProduct.setProductCost("Cost: "+cursor.getString(cursor.getColumnIndex("_Cost")));
cartProduct.setProductPrice("Price: "+cursor.getString(cursor.getColumnIndex("_Price")));
cartProduct.setProductQuantity("Quantity: "+cursor.getString(cursor.getColumnIndex("_Quantity")));
productList.add(cartProduct);
}while(cursor.moveToNext());
}
我正在使用Retrofit2以便将arraylist发送到服务器,但是正如我在其他问题中看到的那样,我无法获取file_get_contents的URL?
I'm using retrofit2 in order to send the arraylist to the server, but as I have seen in other question here I'm not able to get the url for the file_get_contents ?
推荐答案
几乎花了3多个星期和n多个小时的挫败感,我终于找到了解决我的问题的可行解决方案,并与人们分享,以便他们可以从中受益从它(因为我被问了太多的问题和否决票而被另一个A/C挡住了),为了将阵列列表发送到服务器,我们需要使用另一个库,根据我的需要,最合适的方法是async-通过循环j的http库,这些是在程序中导入和使用该库的步骤:-
After almost searching for 3+ weeks and n+ hours of frustration, i've finally found an working solution to my problem and sharing it with people so they could benefit from it (as i was blocked from another a/c due to asking too many questions and down votes ) , in order to send your array list to your server we need to use another library and the best fit according to my need is async-http library by loop j and these are the steps to import and use the library in your program :-
1.)通过在bulid.gradle(应用程序模块)中编写以下语句,将库导入到您的项目中:-
1.)import the library into your project by writing this statement in your bulid.gradle(app module):-
编译'com.loopj.android:android-async-http:1.4.9'
compile 'com.loopj.android:android-async-http:1.4.9'
2.)创建以下变量以便在程序中使用它们:-
2.)Create the following variables in order to use them in your program:-
AsyncHttpClient (a client to send data to your server)
RequestPrarms (Data sent to your server for parsing and further operations )
String url(Link to your server where actually operations occurs)
3.)现在,我们使用这些变量并运行程序:-
3.) Now we use these variables and run the program :-
p
arams.put("OrderSummary", <your array list>);
httpClient.post(APIURL.API_URL,params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
//your operations on success
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_LONG).show();
}
});
我希望这可以消除您的疑虑,我仍在创建我的php端以便在数据库中插入数据
i hope this clears your doubts somewhat i'm still creating my php side in order to insert data in the database
这篇关于PHP:读取json arraylist并在mysql中保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!