无法在html中显示json对象
我试图显示错误消息的通知,但我看到的是带有格式的实际json数据无法在html中显示json对象,json,Json,我试图显示错误消息的通知,但我看到的是带有格式的实际json数据 notificationMsg({ text: data.responseText, type: 'error', hide: false }); 显示的结果是: {“Title”:“Error”,“Message”:“Error with Account login”,“Type”:3,“Data”:null,“Hide”:false,“IsClientMessage”:true,“TypeString”:“Error”} 我
notificationMsg({ text: data.responseText, type: 'error', hide: false });
显示的结果是:
{“Title”:“Error”,“Message”:“Error with Account login”,“Type”:3,“Data”:null,“Hide”:false,“IsClientMessage”:true,“TypeString”:“Error”}
我希望它看起来像这样:
错误帐户登录错误 我试过:
notificationMsg({ text: JSON.parse(data.responseText), type: 'error', hide: false });
但结果是
[Object Object]
如何在没有格式化的情况下正确显示错误消息?您需要解析JSON,请尝试以下代码
objResposneText = JSON.parse(data.responseText);
notificationMsg({ text: objResposneText.Title, type: 'error', hide: false });
notificationMsg({ text: objResposneText.Message, type: 'error', hide: false });
或用于单个通知消息
notificationMsg({ text: objResposneText.Title + " " + objResposneText.Message, type: 'error', hide: false });
尝试添加
var objResposneText=JSON.parse(data.responseText)
beforenotificationMsg({text:objResposneText.Title,键入:'error',hide:false})代码>是的,我意识到我错过了,所以我继续添加它-谢谢你的帮助!!