如何反序列化下面的这个 json 对象?
[{"id":"67","name":"TestString"}]
我尝试在下面执行此操作,但无法成功...
success: function (data, status) {
$.each(data, function (dt) {
var mydata = data.d;
alert(mydata); // returns [{"id":"67","name":"TestString"}]
$("#txt_speciality").tokenInput("add", mydata.id);
});
}
这是我创建 json 对象的方式
[WebMethod]
public static string get_specialities(string ProfessionalID)
{
Database db = DatabaseFactory.CreateDatabase("Connection String2");
DbCommand dbCommand;
dbCommand = db.GetStoredProcCommand("Select_Professionals_Speciality");
db.AddInParameter(dbCommand, "prof_id", DbType.Int16, Convert.ToInt16(ProfessionalID));
IDataReader dr = db.ExecuteReader(dbCommand);
//[{ id: 3, name: "test3" }]
string return_str="[";
int i = 0;
while (dr.Read()) {
if (i > 0)
return_str += ",";
return_str += "{\"id\":\"" + dr["SpecialtyID"].ToString().Trim() + "\",\"name\":\"" + dr["SpecialtyName"].ToString().Trim() + "\"}";
i++;
}
return_str += "]";
return return_str;
}