reactnativeDisplay json文件采用另一种格式



RN中的新秀,谢谢!我想在页面上显示一个JSON文件。

这是JSON的格式:

{
  "prediction": [
            { "name":"egg", "value":"0.95" },
            { "name":"apple", "value":"0.02" },
            { "name":"peach", "value":"0.01" },
            { "name":"orange", "value":"0.01" },
            { "name":"fish", "value":"0.01" }
  ]
}

假设JSON的名称将为"/app/prediction.json"。我在此页面上使用的文本输入方法将是:

import { Tile, List, ListItem, Button } from 'react-native-elements';
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  Dimensions,
  View
} from 'react-native';

export default class ProjectOne extends Component {
  render() {
    return (
      <View style={styles.container}>
       <Text style={styles.text}> Analysis </Text>
       <Text> The object has " 95% possibility to be an egg, 40% to be an apple "</Text>
      </View>
    );
  }

}
const styles = StyleSheet.create({
  text: {
    fontSize: 20,
    fontWeight: 'bold',
  },
  container: {
    height: 275,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  preview: {
   flex: 1,
   justifyContent: 'flex-end',
   alignItems: 'center',
   height: Dimensions.get('window').height,
   width: Dimensions.get('window').width
 },
  capture: {
    flex: 0,
    backgroundColor: 'black',
    borderRadius: 5,
    color: '#ffffff',
    padding: 10,
    margin: 40
  }
});
AppRegistry.registerComponent('ProjectOne', () => ProjectOne);

有什么办法可以获取JSON文件,然后将JSON内容显示在此页面上的该文本字段中?

您可以使用require('./app/prediction.json')进行操作,然后将其转换为字符串或格式,如果需要

相关内容

  • 没有找到相关文章

最新更新