请您告诉我如何提取控制器中字符串变量中收到的JSON数据。请参阅附件。谢谢。
isAppInstalled("com.android.chrome");
private boolean isAppInstalled(String packageName) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
$("#btn1").on("click", function () {
var i = new Array();
var j = 0;
$("#sl1").multiselect("getChecked").map(function () {
alert(this.value);
i.push(this.value);
//i[j] = this.value;
//j++;
}).get();
var postData = { values: i };
jQuery.ajaxSettings.traditional = true;
$.post('/TodoList/searchdata', postData, function (data) {
alert(data.Result);
});
//$.ajax({
// type: "POST",
// url: "/TodoList/searchdata",
// data: postData,
// success: function (data) {
// alert(data.Result);
// },
// dataType: "json",
// traditional: true
//});
});
答案 0 :(得分:0)
您可以使用Newtonsoft Json库https://www.nuget.org/packages/Newtonsoft.Json/
所以如下面的链接所示,请使用下面的内容
string json = @“{'Email':'james@example.com','Active':true, 'CreatedDate':'2013-01-20T00:00:00Z','角色':[ '用户','管理员']}“;
帐户帐号= JsonConvert.DeserializeObject(json);
如果您没有型号,请使用如下所示
var model = JsonConvert.DeserializeObject(json);
检查以下链接
http://www.newtonsoft.com/json/help/html/deserializeobject.htm
答案 1 :(得分:0)
试试这个
JavaScriptSerializer js = new JavaScriptSerializer();
var data=js.Deserialize<Dictionary<string, List<string>>>(i);
答案 2 :(得分:0)
使用此类:
public class JsonAttributeClass<T> where T:class ,new()
{
public static string EntityToJsonConvertor(T entity)
{
string json = JsonConvert.SerializeObject(entity);
return json;
}
public static T JsonToEntityConvertor(string json)
{
var entity = JsonConvert.DeserializeObject<T>(json);
return entity;
}
}