从Mandrill收到的JSON字符串:
[{"事件":" hard_bounce"" _id":" 5760ab383b1b4e358f10cfe759440dce"" MSG&#34 ;: {" TS":1426810207," _id":" 5760ab383b1b4e358f10cfe759440dce""状态":"弹"&# 34;主题":"鸡尾酒会","电子邮件":" XXXXXX@XXX.com.XX","标签": []," smtp_events":[],"重发":[]," _version":" Nes5DEa8tOq5Z6m_b9AWIA",的&# 34; diag":" smtp; 501 5.1.3邮箱地址中的语法错误" XXXXXX@XXX.com.XX" (不可打印的字符)" ," bgtools_code":10," sender":" info-noreply@inviter.com", "模板":null," bounce_description":" bad_mailbox"}," ts":1426822720}]
更新
这是从mandrill收到的另一个无效字符串
[{"事件":" hard_bounce"" _id":" cddb25d2023a486a89454d5c6cefc4c9"" MSG&#34 ;: {" TS":1427904051," _id":" cddb25d2023a486a89454d5c6cefc4c9""状态":"弹"&# 34;主题":" Aniversary Cocktail Party"," email":" XXXXX@XXX.com","标签":[ ]" smtp_events":[],"重发":[]," _version":" CvawLhm-1KO4OY_FsZ3uSA",的& #34; diag":" smtp; 550这里没有这样的用户"" ," bgtools_code":10,"发件人" :" info-noreply@inviter.com","模板":空," bounce_description":" bad_mailbox"}" ts":1427935354}]
预期的JSON字符串:
[
{
"event": "hard_bounce",
"_id": "5760ab383b1b4e358f10cfe759440dce",
"msg": {
"ts": 1426810207,
"_id": "5760ab383b1b4e358f10cfe759440dce",
"state": "bounced",
"subject": "Cocktail Party",
"email": "XXXXXX@XXX.com.XX",
"tags": [],
"smtp_events": [],
"resends": [],
"_version": "Nes5DEa8tOq5Z6m_b9AWIA",
"diag": "smtp;501 5.1.3 Syntax error in mailbox address 'XXXXXX@XXX.com.XX' (non-printable character)",
"bgtools_code": 10,
"sender": "info-noreply@inviter.com",
"template": null,
"bounce_description": "bad_mailbox"
},
"ts": 1426822720
}
]
验证JSON字符串PHP代码:
function validateMandrillJSONString($JSONString){
$JSONString = json_decode($JSONString);
if(is_array($JSONString)){
if(empty($JSONString)){
return FALSE;
}
else{
return TRUE;
}
}
else{
return FALSE;
}
}
问题: 当我将Received JSON字符串发送到上面的PHP函数时,它返回FALSE。然后我发现JSON String With Double Quotes存在问题(" diag":" smtp; 501 5.1.3邮箱地址中的语法错误" XXXXXX @XXX。 com.XX"(不可打印的字符)" )。
不仅是上面的字符串。我有更多类似的字符串。例如,当用户在主题中给出双引号时(嗨" Madhu",你好吗?)我得到同样的错误。
这是来自mandrill还是来自我身边的错误。如果是在我身边,我该如何解决这个问题?
提前致谢。
答案 0 :(得分:0)
我可以这么说,这个bug来自mandrill它自己。我从mandrill获得了无效的JSON。键值" diag" 中的双引号的主要问题。
这是我使用字符串替换的临时修复。
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
class SingleSwitchTopo(Topo):
“Single switch connected to n hosts.”
def_init_(self,n=2,**opts):
#initialize topology and default options
Topo._init_(self,**opts)
switch=self.addSwitch(‘s1’)
#Python’s range(N) generates 0..N-1
for h in range(n):
host=self.addHost(‘h%s’%(h+1))
self.addLink(host,switch)
def simpleTest():
“Create and test a simple network”
topo=SingleSwitchTopo(n=4)
net=Mininet(topo)
net.start
print “Dumping host connections”
dumpNodeConnections(net.hosts)
print “Testing network connectivity”
net.pingAll()
net.stop()
if _name_==’_main_’:
#Tell mininet to print useful information
setLogLevel(‘info’)
simpleTest()
欢迎任何建议
谢谢。