1. .net中Controller里面的方法
/// <summary> /// 流程图 /// </summary> /// <returns>返回对象Json</returns> [HttpGet] public ActionResult GetFlowChartJson() { Dictionary<string, string> newsInfo = new Dictionary<string, string>(); PA_AssessCycleEntity assessCycleEntity = assessCycleBLL.GetEntity(""); string state = assessCycleEntity.State.ToString(); if (state == "0") newsInfo.Add("0", "考核已终止"); else newsInfo.Add("1", "考核已启动"); return ToJsonResult(newsInfo); }
2. json中读取上面的Dictionary,主要是使用for in 读取,如下图所示。
var vList; //获取后台数据:流程图 $.ajax({ url: contentPath + "/Home/GetFlowChartJson", type: "get", dataType: "json", async: false, success: function (data) { vList = data; } }); for (var i in vList) { alert('编码='+i +' 文本='+ vList[i]); }