用咖啡脚本阅读Json

时间:2015-02-11 03:42:47

标签: json coffeescript

在json url中存储了一个java List后,我在这个url / formFields中得到了以下json

["[DATE]","[VOTRE NOM DE COMPAGNIE]","[TYPE DE SOCIETE]","[LOI CONSTITUTIVE/LOI RELATIVE]","[ADRESSE COMPLETE]","[NOM SECOND CONSTITUANT]","[TYPE DE SOCIETE]","[LOI CONSTITUTIVE/LOI RELATIVE]","[ADRESSE COMPLETE]"]

我尝试过并试过但是我没有用这个咖啡脚本来阅读这个Json url:

$ ->
  $.get "/formFields", (formFields) ->
    $.each formFields, (index, field) ->
      $("#formFields").append $("field")

请帮助

1 个答案:

答案 0 :(得分:0)

最终我发现了一个解决方案,我的json格式不正确。我改变了这个:

[{"id":"1","field":"[DATE]"},{"id":"2","field":"[VOTRE NOM DE COMPAGNIE]"},    {"id":"3","field":"[TYPE DE SOCIETE]"},{"id":"4","field":"[LOI CONSTITUTIVE/LOI RELATIVE]"}]. 

现在我的Jquery是:

$ -> 
  $.get "/formFields", (formFields) -> 
    $.each formFields, (index, field) -> 
      $("#formFields").append $("<tr>") 
      $("#formFields").append $("<td>").text field.field
      $("#formFields").append $("<td>").text field.id