Home > Software engineering >  how get value of height in json response
how get value of height in json response

Time:08-10

here I want to get values from the below json response

      console.log('base64 -> ', response.base64);
      console.log('uri -> ', response.uri);
      console.log('width -> ', response.width);
      console.log('height -> ', response.height);
      console.log('fileSize -> ', response.fileSize);
      console.log('type -> ', response.type);
      console.log('fileName -> ', response.fileName);
Response =  {"assets": [{"fileName": "rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg", "fileSize": 52507, "height": 400, "type": "image/jpeg", "uri": "file:///data/user/0/com.vbuild/cache/rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg", "width": 300}]}

CodePudding user response:

response.assets[0].height to get one value but if you have many entries for assets you'd have to iterate over them using .forEach():

response = {
    "assets": [
        {
            "fileName": "rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg",
            "fileSize": 52507,
            "height": 400,
            "type": "image/jpeg",
            "uri": "file:///data/user/0/com.vbuild/cache/rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg",
            "width": 300
        },
        {
            "fileName": "rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg",
            "fileSize": 52507,
            "height": 401,
            "type": "image/jpeg",
            "uri": "file:///data/user/0/com.vbuild/cache/rn_image_picker_lib_temp_fbd53dea-d38f-4a6b-8b12-6ff3ca31cd82.jpg",
            "width": 300
        }
    ]
}

response.assets.forEach(entry => console.log(entry.height))

CodePudding user response:

If you want to get height

const { height } = Response.assets[0]
console.log(height)

And so on you can destructure other props

const { height, fileName, fileSize } = Response.assets[0]
console.log(height, fileName, fileSize)
  • Related