我在一个问题上运行了几个小时,我创建了一个webservice,它返回以下Json字符串(通过在.net中使用JavaScriptSerializer lib:
{"d":"[{\"Id\":4,\"Description\":\"\\u003cp\\u003eExcelente Apartamento com 02 dormit\\u0026oacute;rios, primeiro andar, um lance de escada, de frente, todo reformado, sala, cozinha\/\\u0026aacute;rea de servi\\u0026ccedil;o. Condom\\u0026iacute;nio tradicional, super organizado, com portaria 24h, playground, quadra poliesportiva, Sal\\u0026atilde;o de festa, quiosques\\u003c\/p\\u003e\\r\\n\",\"Price\":\"200000\",\"Address\":\"Avenida Eng Francisco Rodolfo Simch\",\"Rooms\":\"1\",\"Suites\":\"1\",\"Baths\":\"2\",\"Year\":\"2010\",\"Area\":\"63.2\",\"AreaTotal\":\"200\",\"Garage\":\"1\",\"PicturePath\":null,\"Extrainfo\":null,\"ID_Realstate_agency\":0,\"ID_Facilities\":0,\"ID_Neighborhood\":2027,\"ViewCount\":null,\"ID_PropertyType\":1,\"ID_Amenities\":0,\"GeoLoc_Lat\":\"-30.1091\",\"GeoLoc_Lng\":\"51.2519\",\"ID_TYPEDEAL\":1,\"rowcount\":0,\"NeighborhoodName\":\"Agronomia\",\"CityName\":\"PORTO ALEGRE\",\"StateName\":\"Rio Grande do Sul\",\"StateUF\":\"RS\",\"PropertyName\":\"Apartamento Padrão\",\"USER\":{\"ID\":3,\"PHONENUMBER\":\"2147483647\",\"EMAIL\":null,\"NAME\":\"Carlos Linares\"},\"IMAGES\":[{\"Id\":0,\"ID_Product\":4,\"PicturePath\":\"2015\/12\/origin_20151227171214875.jpg\",\"Picture_Order\":1},{\"Id\":0,\"ID_Product\":4,\"PicturePath\":\"2015\/12\/origin_20151227171215347.jpg\",\"Picture_Order\":2},{\"Id\":0,\"ID_Product\":4,\"PicturePath\":\"2015\/12\/origin_20151227171215387.jpg\",\"Picture_Order\":3}]}}
问题在于:
在ASMX Web服务上>根节点是D,这是奇怪的,因为我没有在.net中添加根节点,我只是序列化类
>当我尝试使用
获取Node PRODUCTS的值时productSearchResult.getJSONArray(" PRODUCTS&#34);
我得到一个JSonException:没有产品的价值。我的猜测是JsonObject没有很好地形成,这个对象是一个返回对象,使用方法getBody()使用Webb的HTTP包装器。
答案 0 :(得分:0)
这是我目前用来纠正json结构的方法。
public static String convertStandardJSONString(String data_json) {
data_json = data_json.replaceAll("\\\\r\\\\n", "");
data_json = data_json.replace("\"{", "{");
data_json = data_json.replace("}\",", "},");
data_json = data_json.replace("}\"", "}");
return data_json;
}