2014-11-24 103 views
0

我想显示一条错误消息的通知,但是我所看到的是实际的带格式的json数据。显示麻烦在html中显示json对象

notificationMsg({ text: data.responseText, type: 'error', hide: false }); 

结果是:

{ “标题”: “错误”, “消息”: “错误与帐户登录”, “类型”:3 “数据”:NULL,”隐藏 “:假的,” IsClientMessage “:真实的,” TypeString “:” 错误“}

我想为它看起来像这样:

错误
误差帐户登录

我想:

notificationMsg({ text: JSON.parse(data.responseText), type: 'error', hide: false }); 

但结果是

[Object Object] 

我怎样才能正确地显示错误消息,而无需格式?

回答

1

需要解析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 }); 
+0

尝试添加'变种objResposneText = JSON.parse(data.responseText)单个通知消息;''之前notificationMsg( {text:objResposneText.Title,type:'error',hide:false});' – 2014-11-24 07:40:43

+0

是的,我意识到我错过了,所以我继续并添加它 - 谢谢你的帮助! – user3244544 2014-11-24 07:48:08