2017-02-16 43 views
-1

我有一個AJAX表單提交本的responseText:jQuery的嵌套JSON解析每個循環

"{"form_errors": {"first_name": ["Can only contain a-z, A-Z and -"]}, "messages": [{"message": "dur", "level": 40, "extra_tags": "danger"}]}" 

我需要能夠遍歷所有form_errors如:

  $.each(errors, function(index, value) 
      { 
       if (index !== "__all__") 
       { 
        apply_form_field_error(index, value); 
       } 
      }); 

我曾嘗試: var errors = JSON.parse(data.responseText ['form_errors']); 試圖讓自己的東西循環但無法以適當的方式訪問form_errors循環。

任何想法?

非常感謝

回答

1

解析使用

var response = JSON.parse(str) 

整個字符串,然後使用

response.form_errors 

注意,當前字符串不正確轉義

+0

感謝訪問。剛纔我也明白了。非常感謝 – user1496093