假设我在字符串数组中存储了一个名称列表,例如:“abc”、“bcd”、“gdf”...。我有一个 Android 应用程序,它显示每个值以及一个复选框。我需要将我的字符串数组转换为 JSON 字符串,以便可以将其存储在远程数据库中。现在我正在使用使用 SQL Server 创建的数据库在 localhost 上工作。我需要使用 Web 服务在数据库中插入 JSON 字符串值,最好是 SOAP
我该怎么做?还有其他更好的方法吗?
这是我的安卓代码。
谢谢
假设我在字符串数组中存储了一个名称列表,例如:“abc”、“bcd”、“gdf”...。我有一个 Android 应用程序,它显示每个值以及一个复选框。我需要将我的字符串数组转换为 JSON 字符串,以便可以将其存储在远程数据库中。现在我正在使用使用 SQL Server 创建的数据库在 localhost 上工作。我需要使用 Web 服务在数据库中插入 JSON 字符串值,最好是 SOAP
我该怎么做?还有其他更好的方法吗?
这是我的安卓代码。
谢谢
就我而言,这很好用,
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", value1);
jsonObject.put("key2", value2);
JSONArray jArrayParam = new JSONArray();
jArrayParam.put(jsonObject);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("bulkdata",
jArrayParam.toString()));
Log.e("bulkdata", jArrayParam.toString());
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("yor remote database url");
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
// get response entity
HttpEntity entity = response.getEntity();
尝试一下。谢谢。
好吧,我只是想向您展示如何将 String 数组写入 JSONObject 和 JSONArray。
String arr[] = {"1","parth","present","30-82011","Mumbai"};
try {
JSONObject obj=new JSONObject();
obj.put("rollno",new Integer(arr[0]));
obj.put("status",arr[1]);
obj.put("date",arr[2]);
obj.put("place",arr[3]);
System.out.print(obj.toString(1));
JSONArray list = new JSONArray();
list.put(arr[0]);
list.put(arr[1]);
list.put(arr[2]);
list.put(arr[3]);
System.out.print(list.toString(1));
System.out.println("");
} catch (Exception e) {
e.printStackTrace();
}
var arr:String = com.adobe.serialization.json.JSON.encode(Obj);
var data_projects:Array = stmt.getResult().data;
var b_data:String = com.adobe.serialization.json.JSON.encode(data_projects);
var arr:String = com.adobe.serialization.json.JSON.encode(data_projects);
var arr1:Object = com.adobe.serialization.json.JSON.decode(b_data) as Array;
for(var d:int=0;d<=data_projects.length-1;d++)
{
//Mapping properties of Proxy classes with actual fields
var bbb:Object = new Object;
data.MdId = arr1[d].MD_ID;
data.MdDevId=arr1[d].MD_DEVICE_ID;
data.MdRecId=arr1[d].MD_REC_ID;
data.MdPrjId= arr1[d].MD_PRJ_ID ;
data.MdMbcId = arr1[d].MD_MBC_ID;
data.MdMbcValue= arr1[d].MD_MBC_VALUE;
data.MdParentRecId= arr1[d].MD_MBC_ID;
//below is the create method on the WSDL
ws.Create(data);
}