从JAVA发送JSON时,它只是一行(虽然它显示多行)
[{"contactId":"1","contactPhoto":"iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAA3NCSVQFBgUzC42AAAAAIUlEQVQI\nmWM0VFFkYGFgYGBgYmD4zsEAZXH+YPjO8IcBACqeBHPlr5Z8AAAAAElFTkSuQmCCiVBORw0KGgoA\nAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAA3NCSVQFBgUzC42AAAAAIUlEQVQImWM0VFFkYGFg\nYGBgYmD4zsEAZXH+YPjO8IcBACqeBHPlr5Z8AAAAAElFTkSuQmCC\n","displayName":"Pree","key":"P"}]
但是在javascript中,当我解析JSON时,由于我认为它是无效的JSON,因此我无法解析多个lnes。
07-18 19:28:38.842: DEBUG/HTMLContacts(1675): JS Start at: 1311042518617json[{"contactId":"1","contactPhoto":"iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAA3NCSVQFBgUzC42AAAAAIUlEQVQI
07-18 19:28:38.842: DEBUG/HTMLContacts(1675): mWM0VFFkYGFgYGBgYmD4zsEAZXH+YPjO8IcBACqeBHPlr5Z8AAAAAElFTkSuQmCCiVBORw0KGgoA
07-18 19:28:38.842: DEBUG/HTMLContacts(1675): AAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAA3NCSVQFBgUzC42AAAAAIUlEQVQImWM0VFFkYGFg
07-18 19:28:38.842: DEBUG/HTMLContacts(1675): YGBgYmD4zsEAZXH+YPjO8IcBACqeBHPlr5Z8AAAAAElFTkSuQmCC
如何解决这个问题?我很困惑。
答案 0 :(得分:2)
我认为问题在于换行符 - \n
转义字符(以及您最终可能遇到的其他转义字符)。这是在另一篇文章中回答的。请参阅以下内容:How to escape a JSON string containing newline characters using javascript?