android parse json after optimize php json_encode -
android parse json after optimize php json_encode -
there arrays in arrays:
array ( [0] => array ( [0] => v1 [1] => v2 [2] => v3 ) [1] => array ( [0] => v1 [1] => v2 [3] => v3 ) [2] => array ( [0] => v1 [1] => v2 [10] => v3 ) [4] => array ( [0] => v1 [1] => v2 [3] => v3 ) )
after json_encode
on andorid following:
{ «0»: [ «v1», «v2», «v3» ], «1»: { «0»:«v1», «1»:«v2», «3»:«v3», }, «2»: { «0»:«v1», «1»:«v2», «10»:«v3» }, «4»: { «0»:«v1», «1»:«v2», «3»:«v2» } } jsonarray jlist = jb.getjsonarray(response); //exception not array
is there way parse array[array[]]
on android?
this happens because have non-contiguous indices. if "renumber" array
$a = array_values($a);
you have
array ( [0] => array ( [0] => v1 [1] => v2 [2] => v3 ) [1] => array ( [0] => v1 [1] => v2 [3] => v3 ) [2] => array ( [0] => v1 [1] => v2 [10] => v3 ) [3] => array ( [0] => v1 [1] => v2 [3] => v3 ) )
and result json_encode
create
[ ["v1", "v2", "v3"], { "0": "v1", ...}, ... ]
if want have inner arrays too, must ensure inner arrays have contiguous indices well.
if can't alter php code, way parse json object , iterate on properties using keys()
, pick values individually.
android json
Comments
Post a Comment