我有一个创建 JSONArray 的 android 应用程序:
List<String[]> sqlist = MySQLiteHelper.selectAll();
JSONArray jsArray = new JSONArray(sqlist);
哪个在呼唤
public static List<String[]> selectAll()
{
List<String[]> list = new ArrayList<String[]>();
Cursor cursor = db.query(TABLE_BREADCRUMBS, new String[]
{ "id","tim","lat","lon"}, null, null, null, null, null);
int x=0;
if (cursor.moveToFirst()) {
do {
String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2),
cursor.getString(3)};
list.add(b1);
x=x+1;
} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
cursor.close();
return list;
}
然后我试图调用看起来像的网络服务 BoldApi
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class BoldApi
Inherits System.Web.Services.WebService
Dim b_id As Integer
Dim b_time As String
Dim b_lat As String
Dim b_lon As String
Public Property idBreadcrumb() As Integer
Get
Return b_id
End Get
Set(ByVal value As Integer)
b_id = value
End Set
End Property
Public Property timeBreadcrumb() As String
Get
Return b_time
End Get
Set(ByVal value As String)
b_time = value
End Set
End Property
Public Property latBreadcrumb() As String
Get
Return b_lat
End Get
Set(ByVal value As String)
b_lat = value
End Set
End Property
Public Property lonBreadcrumb() As String
Get
Return b_lon
End Get
Set(ByVal value As String)
b_lon = value
End Set
End Property
<WebMethod()> _
Public Function JSONpass(ByVal jsArray() As BoldApi) As Boolean
For X = 0 To jsArray.Length - 1
' Usage example
b_id = jsArray(X).idBreadcrumb()
b_time = jsArray(X).timeBreadcrumb()
b_lat = jsArray(X).latBreadcrumb()
b_lon = jsArray(X).lonBreadcrumb()
InsertRow(b_time, b_lat, b_lon)
Next
Return True
End Function
Public Sub InsertRow(time As String, lat As String, lon As String)
Dim myConnectionString As String = "Data Source=tcp:sql2k804.discountasp.net;Initial Catalog=SQL2008R2_868128_mjk;User ID=********;Password=******;"
Dim myConnection As New SqlConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO dbo.bold_breadcrumbs (latitude, longitude) values (lat,lon)"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub 'SelectSqlClientSrvRows
End Class
通过使用看起来像的 HttpPost
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.gamoda.org/r/Bold/api/BoldApi.asmx");
try {
httppost.setEntity((HttpEntity) jsArray);
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我收到错误:java.lang.ClassCastException: org.json.JSONArray