2014-02-12 93 views
0

大家好! 我控制器从MVC控制器创建Json数组

public JsonResult GetPlacesJson() 
     { 
      var result = myplaces.GetAllPlaces();   //return List 
      return Json(result,JsonRequestBehavior.AllowGet); 
     } 

我需要创建一个JavaScript数组与JSON对象使用controller.I试图用$ .getJson(...),但我没有succeed.Could你能帮我吗? 谢谢!

+0

就得到一个正常指定回报 –

回答

0

试试这个,

 
       JsonArray places = new JsonArray(); 

       for (String s : myplaces.GetAllPlaces();) { 
        places.add(new JsonPrimitive(s)); 
       } 
0

使用下面的代码创建从JSON Javascript数组:

<script> 
    var rows = []; 
    for (var i = 0; i < jsonresult.length; i++) { 
    rows.push.apply(rows, jsonresult[i]); 
    } 
    </script>