weixin_33734785 2015-10-15 03:12 采纳率: 0%
浏览 38

解析JSON对象

How I can parse 2 JSON objects? e.g

AJAX return just one Object appear's correctly.

Object {32 : "Joseph"} 

But, when return more than 2 objects, I've got this:

ResponseText:  "{"users":{"32":"Jospeh"}}{"users":{"48":"Jospeh K."}}"

I already trieD to parse with JSON.parse but returns an error: "Uncaught SyntaxError: Unexpected token {"

So, How I can parse to return something like this:?

 Object {32 : "Joseph"} 
 Object {48 : "Joseph K"} 

Instead of "responseText"

Considerations:

  1. If returns just ONE object, appears correctly in console(example);
  2. If returns more than TWO objects, appears responseText;
  3. AJAX dataType: JSON

I'll be very grateful if someone can help with this. =D

PHP:

public function get_error_message()
{

    $message = "";
    foreach ($this->errors as $value) {

        if ($value instanceof UsersError) {
            $message.= json_encode(array('errors' => array($value->getCode() => $value->getMessage())));

        }
    }

    return $message;
}
  • 写回答

4条回答 默认 最新

  • weixin_33676492 2015-10-15 03:24
    关注

    That's not a valid JSON object. It is 2 JSON object in string representation concatenated together, which as far as I know is not valid. If you can't change the back-end, and you have to process this and can guarantee it is always 2 JSON object concatenated together, then you'll have to use string parsing to split them before sending them into JSON.parse(...) individually to get 2 JSON objects back.

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元