Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从多部分HTTP响应中提取多个JSON字符串_Java_Json_Apache Httpclient 4.x_Apache Httpcomponents_Apache Commons Fileupload - Fatal编程技术网

Java 从多部分HTTP响应中提取多个JSON字符串

Java 从多部分HTTP响应中提取多个JSON字符串,java,json,apache-httpclient-4.x,apache-httpcomponents,apache-commons-fileupload,Java,Json,Apache Httpclient 4.x,Apache Httpcomponents,Apache Commons Fileupload,我使用ApacheHttpClient处理一个web服务,该服务返回一个包含json的多部分/表单数据响应 我很难分别提取每个JSON字符串,以便读取JSON字符串 我确实读过关于Stackoverflow的类似文章,有些人建议使用ApacheCommonsFileUpload,但我不确定如何将JSON字符串与包含大量其他文本(如边界字符串、内容类型等)的整个响应分开 响应如下所示 --Boundary_16003419_2104021487_1483424496169 Content-Type

我使用ApacheHttpClient处理一个web服务,该服务返回一个包含json的多部分/表单数据响应

我很难分别提取每个JSON字符串,以便读取JSON字符串

我确实读过关于Stackoverflow的类似文章,有些人建议使用ApacheCommonsFileUpload,但我不确定如何将JSON字符串与包含大量其他文本(如边界字符串、内容类型等)的整个响应分开

响应如下所示

--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetMailboxes
Status-Code: 200
X-Server-Response-Time: 4ms
X-Server-Chain: domain.com
Content-RequestDuration: 5

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetFolders
Status-Code: 200
X-Server-Response-Time: 8ms
X-Server-Chain: domain.com
Content-RequestDuration: 10

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAlerts
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAccounts
Status-Code: 200
X-Server-Response-Time: 11ms
X-Server-Chain: domain.com
Content-RequestDuration: 12

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAllSavedSearches
Status-Code: 200
X-Server-Response-Time: 10ms
X-Server-Chain: domain.com
Content-RequestDuration: 12

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetAthenaSegment
Status-Code: 200
X-Server-Response-Time: 14ms
Content-RequestDuration: 21

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: ListFolderThreads
Status-Code: 200
X-Server-Response-Time: 110ms
Content-RequestDuration: 116

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-Type: application/json
Content-RequestId: GetUserInfo
Status-Code: 200
X-Server-Response-Time: 197ms
Content-RequestDuration: 204

{JSON}
--Boundary_16003419_2104021487_1483424496169
Content-RequestId: Status
Content-Type: application/json

{JSON}
--Boundary_16003419_2104021487_1483424496169--

有什么可靠的方法可以做到这一点吗?

一个选择是。如果希望应用程序在不在内存中构建完整的DOM树的情况下处理响应内容,则可能需要使用所述的
MimeTokenStream
MimeStreamParser

您的请求是什么样的?您正在请求
应用程序/json
?这是响应的完整开始吗?它看起来不正确,
内容类型
应该包含边界标记。您如何使用httpclient读取响应数据?@PeterMmm我请求“application/json;charset=utf-8”我已经编辑了问题并发布了完整的响应。这就是JSON内容更改为{JSON}时100%的情况。响应以
--Boundary\u 16003419…
开始?这个服务器是什么?你能控制它吗?@petermm不幸的是我不能控制它。不过我必须使用它:(我刚刚使用了下面的正则表达式(\\{.*.\})——看起来工作正常