javascript - JS+REST+NodeJS: How to parse a JSON list from a JSON object -
in python have json object, inside fields there 1 (field3) contains list of json objects.
this object passed python script rest service based in js express framework:
urllib.request.urlopen( urllib.request.request( url="http://"+self.__host+_":"+self.__port+"/api"+restmethod, data=urllib.parse.urlencode(objdata).encode('utf8'), headers=self.__headertoken,method=httpmethod) )
but when server receives json automatically recognizes field33 string instead of json list.
{ field1: '', field2: '', field3: '[{\'field31\': \'\', \'field32\': \'\', \'field33\':\'\',\'field34\': \'\', \'field34\': \'0.00\'}]', field4: '' }
so when try obj.field3[0] returns string rather json list.
i tried json.parse(string)
, json.stringify(object)
still cannot access json list , elements obj.field3.field31
how can recover json list parent json field? thanks
field3
should be:
'[{\"field31\": \"\",...}]',
or simply:
'[{"field31": "",...}]',
single quote '
cause error when parsed json.parse.
and obj.field3
array, field31
value, should use:
obj.field3[0].field31
Comments
Post a Comment