Need to send the values of a Sqlite table to the server via an AJAX call to a web service. I can't figure out how to package the rows of this table in a way that the web service will accept it.
Web Method Signature
[WebMethod]
public void CVW(string[][] qAndA)
{}
Client Side
var qAndA = new Array();
tx.executeSql("Select * From CVW Where CallNumber=?", [call], function (tx, result) {
var i = 0;
$.each(result.rows, function () {
qAndA[i] = result.rows.item(i);
i++;
});
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
url: "Service.asmx/CVW",
data: JSON.stringify({ qAndA: qAndA }),
success: function (data) {
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}, onSQLError);
This gives me No parameterless constructor defined for type System.String
. I've tried changing the web method parameter to just string[] and List and same thing.
When I look at what is being sent in Fire Bug I see that it is sending over as Object[object Object][object Object][object Object]...
for as many [object Object]
as there are rows returned in the Sqlite Query. What is the corresponding type in C# that I can use as my parameter type?
EDIT: Final Solution
In the javascript I had to change
data: JSON.stringify({ qAndA: qAndA }),
to
var json = JSON.stringify(qAndA);
data: JSON.stringify({ qAndA: json });
and changed the Web Method thusly
[WebMethod]
public void CVW(string qAndA)
JavaScriptSerializer ser = new JavaScriptSerializer();
List<CVWQuestion> list = ser.Deserialize<List<CVWQuestion>>(qAndA);
[Serializable]
public class CVWQuestion
{
public string CallNumber {get;set;}
public string Question { get; set; }
public string P1 { get; set; }
public string P2 { get; set; }
public string P3 { get; set; }
public string P4 { get; set; }
public string P5 { get; set; }
public string P6 { get; set; }
}