Hi;
I'm building a .NET web service that my application will consume. I've built the service to deliver JSON data. Using the .NET serializer the data looks like this:
Here's the web service:
Here is my javascript as it stands:
The problem I have is that the data array is wrapped in a <string>. How do I modify my datasource (or the web service) to provide just the array so that I can directly read the "title" and "value"? I'd like to drop something into the datasource schema but I don't know what will strip off the <string>.
Thanks!
I'm building a .NET web service that my application will consume. I've built the service to deliver JSON data. Using the .NET serializer the data looks like this:
<
string
xmlns
=
"http://yaddayaddayadda.com/"
>
[{"title":"Stuff","value":"Here's some stuff"}]
</
string
>
Here's the web service:
[WebService(Namespace =
"http://yaddayaddayadda.com/"
)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(
false
)]
[ScriptService]
public
class
websiteWebService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public
string
GetStuff(
int
stuff_id)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"stuff"
].ConnectionString);
connection.Open();
SqlCommand command =
new
SqlCommand(
"o_get_stuff"
, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue(
"@stuff_id"
, stuff_id);
SqlDataReader dr = command.ExecuteReader();
DataTable dt =
new
DataTable(
"Stuff"
);
dt.Load(dr);
dr.Close();
connection.Close();
List<Dictionary<
string
,
object
>> rows =
new
List<Dictionary<
string
,
object
>>();
Dictionary<
string
,
object
> row =
new
Dictionary<
string
,
object
>();
foreach
(DataRow datarow
in
dt.Rows)
{
row =
new
Dictionary<
string
,
object
>();
foreach
(DataColumn col
in
dt.Columns)
{
row.Add(col.ColumnName, datarow[col]);
}
rows.Add(row);
}
JavaScriptSerializer serializer =
new
JavaScriptSerializer();
string
jsonData = serializer.Serialize(rows);
return
jsonData;
}
}
}
Here is my javascript as it stands:
<script type=
"text/javascript"
>
$(document).ready(
function
() {
$(
"#stuffSelector"
).kendoDropDownList({
dataTextField:
"title"
,
dataValueField:
"value"
,
dataSource: {
transport: {
read: {
contentType:
"application/json"
,
type:
"POST"
,
url:
"
http://localhost:23035/Services/websiteWebService.asmx/GetStuff"
,
data: {
stuff_id:
"0"
}
}
}
}
});
});
</script>
The problem I have is that the data array is wrapped in a <string>. How do I modify my datasource (or the web service) to provide just the array so that I can directly read the "title" and "value"? I'd like to drop something into the datasource schema but I don't know what will strip off the <string>.
Thanks!