React-Native

时间:2018-08-30 19:56:07

标签: json react-native

我有一个函数给我这个JSON:

{
   "ImageWidth":3000,
   "ImageHeight":2002,
   "Orientation":1,
   "originalUri":"IMG_0005.JPG",
   "exif":{
      "{TIFF}":{
         "Model":"NIKON D800E",
         "ResolutionUnit":2,
         "Software":"Aperture 3.4.5",
         "Artist":"Nicolas Cornet",
         "DateTime":"2012:08:08 14:55:30",
         "XResolution":72,
         "Orientation":1,
         "Copyright":"Nicolas Cornet",
         "Make":"NIKON CORPORATION",
         "YResolution":72
      }
   }
}

谁能告诉我如何在React-Native(TypeScript)中访问{TIFF}?

Json.exif.TIFF不起作用!

TIFF周围的花括号/大括号有什么作用?谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用方括号放置字符串文字/变量以访问json值

let data = {"ImageWidth":3000,"ImageHeight":2002,"Orientation":1,"originalUri":"IMG_0005.JPG","exif":{"{TIFF}":{"Model":"NIKON D800E","ResolutionUnit":2,"Software":"Aperture 3.4.5","Artist":"Nicolas Cornet","DateTime":"2012:08:08 14:55:30","XResolution":72,"Orientation":1,"Copyright":"Nicolas Cornet","Make":"NIKON CORPORATION","YResolution":72}}}

console.log(data.exif["{TIFF}"])