java - Reading lots of data returned by API -
i reading api provided company, problem 1 of accounts getting data has around 22000 json objects, reads fine small amounts of data, 8000 records, issues json not formatted besides problem of being able read response.
the response comes way:
<?xml version="1.0" encoding="utf-8"?> <string xmlns="http://ywers.com"> [{"name":"edward", "lastname":"jones", "address":"{accepted}"} ,{"name":"carlos", "lastname":"ramirez", "address":"{rejected}"}, ....... 22k more records here]</string>
i asked earlier on here best way this, , got response reading using xml parser , json parser, using gson.
string xml = "<your xml response>"; xpathexpression xpath = xpathfactory.newinstance() .newxpath().compile("/*[local-name()='string']"); string json = xpath.evaluate(new inputsource(new stringreader(xml)));
and
jsonarray jsonroot = new jsonarray(json.trim()); system.out.println(jsonroot.getjsonobject(0).getstring("address")); // {accepted}
the problem approach having throws errors when reading xml, starts reading after while stops errors like:
java.lang.outofmemoryerror @ java.lang.abstractstringbuilder.enlargebuffer(abstractbuilder.java:94) @ java.lang.stringbuffer.append(stringbuffer.java:219) @ org.apache.harmony.xml.dom.characterdataimpl.appenddata(characterdataimpl.java:43) ......
i appreciate advise on how proceed this, kind of new android.
i don't know wrap 22k objects inside xml string, apparently doing that. experience, out of memory because try convert response string response big handled. recommend stream json data. can stream json data inputstream response http post, need skip xml part creating input stream original response input stream , skip xml part
before use streaming api google gson got oom error because json data got big data (many images , sounds in base64 encoding) gson streaming can overcome error because reads data per token not @ once. , alternative can use jackson json library think have streaming api , how use same implementation google gson. hope answer can , if have question answer feel free ask in comment :)
Comments
Post a Comment