在PHP中解析转换为GSON字符串的Java ArrayList
我使用MultipartEntityBuilder将包含JSON对象的Java ArrayList发送到PHP网页。我正在使用GSON将ArrayList转换为字符串,以便将数据发送到PHP网页。这一切都很好。这是我的Java代码:在PHP中解析转换为GSON字符串的Java ArrayList,java,php,json,arraylist,Java,Php,Json,Arraylist,我使用MultipartEntityBuilder将包含JSON对象的Java ArrayList发送到PHP网页。我正在使用GSON将ArrayList转换为字符串,以便将数据发送到PHP网页。这一切都很好。这是我的Java代码: for(List<JSONObject> rows: listOfValidationReports){ HttpPost httppost = new HttpPost(url); Gson gson =
for(List<JSONObject> rows: listOfValidationReports){
HttpPost httppost = new HttpPost(url);
Gson gson = new Gson();
String rowsString = gson.toJson(rows);
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder
.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addTextBody("validationReportRows", rowsString);
httppost.setEntity(multipartEntity.build()); // Set parameter
HttpResponse response = client.execute(httppost, httpContext);
}
我的问题是,当我将这些数据发送到PHP时,我不确定如何解析它并将其放入可以使用的PHP结构中。有很多关于如何发送数据的答案,但找不到任何关于如何在PHP中实际解析数据的答案
我是否需要构建某种正则表达式匹配器来从数组中提取每个JSON对象,或者是否有方法将字符串转换回PHP ArrayList等价物,在该等价物中我可以循环遍历列表中的每个JSON对象。谢谢不要自己滚动,使用内置功能。它将递归您发送的内容,并创建适当的对象、数组、关联数组等…可能的副本
[{"map":{"severity":"WARNING","offset":11902,"column":9,"length":22,"resourceUri":"test-fm.txt","lineNumber":411,"message":"Enum name should be less than 20 characters"}},{"map":{"severity":"WARNING","offset":12329,"column":9,"length":21,"resourceUri":"test-fm.txt","lineNumber":431,"message":"Enum name should be less than 20 characters"}},{"map":{"severity":"WARNING","offset":12544,"column":9,"length":39,"resourceUri":"test-fm.txt","lineNumber":441,"message":"Enum name should be less than 20 characters"}},{"map":{"severity":"WARNING","offset":12672,"column":9,"length":21,"resourceUri":"test-fm.txt","lineNumber":446,"message":"Enum name should be less than 20 characters"}},{"map":{"severity":"WARNING","offset":393,"column":3,"length":134,"resourceUri":"test-types-test@2016-06-01.txt","lineNumber":19,"message":"y extesion, version is missing"}}]