admin管理员组文章数量:1388172
How to convert JSON to plain text?
{"Days":["is not a number"]}
to Days is not a number.
Here is the code:
$('.best_in_place').bind("ajax:error", function(jqXHR,error, errorThrown) {
alert(error.responseText);
});
How to convert JSON to plain text?
{"Days":["is not a number"]}
to Days is not a number.
Here is the code:
$('.best_in_place').bind("ajax:error", function(jqXHR,error, errorThrown) {
alert(error.responseText);
});
Share
Improve this question
edited Sep 9, 2013 at 16:23
insertusernamehere
23.6k10 gold badges91 silver badges128 bronze badges
asked Sep 9, 2013 at 16:16
BrunoBruno
6,47917 gold badges71 silver badges105 bronze badges
1
-
is it always a object with a
key-value
pair, and the value is a array with a length of one? – Math chiller Commented Sep 9, 2013 at 16:20
3 Answers
Reset to default 2Convert the response into JSON object and parse its key-value pair
var error = JSON.parse( error.responseText );
for( var name in error ) {
console.log( name + " " + error[ name ] ); // Days is not a number
}
As you're using jQuery, this might help:
var result = '';
$.each(error.responseText, function(key, value) {
result += key + ' ' + value;
});
This will also work and can easily be adjusted if the response holds multiple key-value-pairs.
Demo
Try before buy
Use json-to-plain-text npm module
本文标签: javascriptHow to convert json to plain textStack Overflow
版权声明:本文标题:javascript - How to convert json to plain text? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744559114a2612660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论