解析“流式传输".JSON格式 [英] Parsing "Streaming" JSON

查看:69
本文介绍了解析“流式传输".JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览器中有一个网格.

I have a grid in a browser.

我想通过JSON将数据行发送到网格,但是浏览器应在接收到JSON时不断对其进行解析,并在解析时将行添加到网格中.换句话说,不应在接收到整个JSON对象之后立即将所有行添加到网格中,而应在接收到它们时将它们添加.

I want to send rows of data to the grid via JSON, but the browser should continuously parse the JSON as it receives it and add rows to the grid as they are parsed. Put another way, the rows shouldn't be added to the grid all at once after the entire JSON object is received -- they should be added as they are received.

这可能吗?尤其是使用jQuery,Jackson和Spring 3 MVC?

Is this possible? Particularly using jQuery, Jackson, and Spring 3 MVC?

这个想法有名字吗?我只在网上稀疏地记录了这个想法的一部分.

Does this idea have a name? I only see bits of this idea sparsely documented online.

推荐答案

您无法使用浏览器的 JSON.parse 解析不完整或无效的JSON.如果您正在流式传输文本,它将始终尝试在某些时候解析无效的JSON,这将导致文本失败.那里有流式JSON解析器,您也许可以找到满足您需求的内容.

You can't parse incomplete or invalid JSON using the browser's JSON.parse. If you are streaming text, it will invariably try and parse invalid JSON at some point which will cause it to fail. There exists streaming JSON parsers out there, you might be able to find something to suit your needs.

在您的情况下,最简单的方法仍然是为每一行发送完整的JSON文档.

Easiest way in your case would remain to send complete JSON documents for each row.

这篇关于解析“流式传输".JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆