1

I have my JSON file in the DocumentDirectoryPath, JSON file looks like

{
    "name": {
        "en_EN": "Epic App Dev Self"
    },
    "description": {
        "en_EN": ""
    },
    "type": "course",
    "id": "epicdevself",
    "value": {
        "version": "1.0.1",
        "series_prefix": "eds"
    },
    "uid": "epicdevself/1.0.1",
    "children": [{
        "name": {
            "en_EN": "Level 1"
        },
        "description": {
            "en_EN": ""
        },
        "type": "level",
        "id": "level1",
        "value": {
            "cover": {
                "targetLanguage": ""
            }
        },
        "uid": "epicdevself/1.0.1/level1",
        "children": [{
            "name": {
                "en_EN": "Unit 1"
            },
            "description": {
                "en_EN": ""
            },
            "type": "unit",
            "id": "unit1",
            "value": {
                "cover": {
                    "teacher": "https://origin-dashboard.com/CDN/ProdStore/EPIC_APP/packets.zip",
                    "targetLanguage": ""
                }
            },
            "uid": "epicdevself/1.0.1/level1/unit1",
            "children": [{
                    "name": {
                        "en_EN": "Lesson 1"
                    },
                    "description": {
                        "en_EN": ""
                    },
                    "type": "lesson",
                    "id": "lesson1",
                    "value": {
                        "targetLanguage": ""
                    },
                    "uid": "epicdevself/1.0.1/level1/unit1/lesson1",
                    "children": [{
                            "name": {
                                "en_EN": "Listening and speaking"
                            },
                            "description": {
                                "en_EN": ""
                            },
                            "type": "resource_group",
                            "id": "skill2",
                            "value": {
                                "display_mode": "icons"
                            },
                            "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill2",
                            "children": [{
                                "name": {
                                    "en_EN": "Listening activity"
                                },
                                "description": {
                                    "en_EN": ""
                                },
                                "type": "activity",
                                "id": "activity3",
                                "value": {
                                    "header": "",
                                    "learningObject": null,
                                    "iconUrl": "",
                                    "teachingNotes": "",
                                    "tincanIri": "",
                                    "activityRubric": "",
                                    "audioScript": "",
                                    "activityUri": "",
                                    "pageBook": "",
                                    "time": 0
                                },
                                "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill2/activity3",
                                "children": [

                                ]
                            }]
                        },
                        {
                            "name": {
                                "en_EN": "Conversation"
                            },
                            "description": {
                                "en_EN": ""
                            },
                            "type": "resource_group",
                            "id": "skill3",
                            "value": {
                                "display_mode": "icons"
                            },
                            "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill3",
                            "children": [{
                                "name": {
                                    "en_EN": "Conversation Activity"
                                },
                                "description": {
                                    "en_EN": ""
                                },
                                "type": "activity",
                                "id": "activity4",
                                "value": {
                                    "header": "",
                                    "learningObject": null,
                                    "iconUrl": "",
                                    "teachingNotes": "",
                                    "tincanIri": "",
                                    "activityRubric": "",
                                    "audioScript": "",
                                    "activityUri": "",
                                    "pageBook": "",
                                    "time": 0
                                },
                                "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill3/activity4",
                                "children": [

                                ]
                            }]
                        },
                        {
                            "name": {
                                "en_EN": "Vocabulary"
                            },
                            "description": {
                                "en_EN": ""
                            },
                            "type": "resource_group",
                            "id": "skill1",
                            "value": {
                                "display_mode": "icons"
                            },
                            "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill1",
                            "children": [{
                                    "name": {
                                        "en_EN": "Vocabulary Activity A"
                                    },
                                    "description": {
                                        "en_EN": ""
                                    },
                                    "type": "activity",
                                    "id": "activity1",
                                    "value": {
                                        "header": "",
                                        "learningObject": {
                                            "uri": "",
                                            "source": null
                                        },
                                        "iconUrl": "",
                                        "teachingNotes": "",
                                        "tincanIri": "",
                                        "activityRubric": "",
                                        "audioScript": "",
                                        "activityUri": "",
                                        "pageBook": "",
                                        "time": 0
                                    },
                                    "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill1/activity1",
                                    "children": [

                                    ]
                                },
                                {
                                    "name": {
                                        "en_EN": "Vocabulary Activity B"
                                    },
                                    "description": {
                                        "en_EN": ""
                                    },
                                    "type": "activity",
                                    "id": "activity2",
                                    "value": {
                                        "header": "",
                                        "learningObject": {
                                            "uri": "",
                                            "source": null
                                        },
                                        "iconUrl": "",
                                        "teachingNotes": "",
                                        "tincanIri": "",
                                        "activityRubric": "",
                                        "audioScript": "",
                                        "activityUri": "",
                                        "pageBook": "",
                                        "time": 0
                                    },
                                    "uid": "epicdevself/1.0.1/level1/unit1/lesson1/skill1/activity2",
                                    "children": [

                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "name": {
                        "en_EN": "Lesson 2"
                    },
                    "description": {
                        "en_EN": ""
                    },
                    "type": "lesson",
                    "id": "lesson2",
                    "value": {
                        "teacher": "https://origin-dashboard.com/CDN/ProdStore/EPIC_APP/packets.zip",
                        "targetLanguage": ""
                    },
                    "uid": "epicdevself/1.0.1/level1/unit1/lesson2",
                    "children": [

                    ]
                },
                {
                    "name": {
                        "en_EN": "Lesson 3"
                    },
                    "description": {
                        "en_EN": ""
                    },
                    "type": "lesson",
                    "id": "lesson3",
                    "value": {
                        "teacher": "https://origin-dashboard.com/CDN/ProdStore/EPIC_APP/packets.zip",
                        "targetLanguage": ""
                    },
                    "uid": "epicdevself/1.0.1/level1/unit1/lesson3",
                    "children": [

                    ]
                },
                {
                    "name": {
                        "en_EN": "Audio"
                    },
                    "description": {
                        "en_EN": ""
                    },
                    "type": "lesson",
                    "id": "audio1",
                    "value": {
                        "targetLanguage": ""
                    },
                    "uid": "epicdevself/1.0.1/level1/unit1/audio1",
                    "children": [

                    ]
                },
                {
                    "name": {
                        "en_EN": "Video"
                    },
                    "description": {
                        "en_EN": ""
                    },
                    "type": "lesson",
                    "id": "video1",
                    "value": {
                        "targetLanguage": ""
                    },
                    "uid": "epicdevself/1.0.1/level1/unit1/video1",
                    "children": [

                    ]
                }
            ]
        }]
    }]
}

From this i need to print the key https://origin-dashboard.com/CDN/ProdStore/EPIC_APP/packets.zip , How to get this key from the above JSON

3
  • Can you show the code explaining how to trying to access this JSON Commented Aug 18, 2017 at 7:02
  • You don't need React Native to do that. Pure JS already has everything you need. Commented Aug 18, 2017 at 7:14
  • I am developing a hybrid app using react native I dont no how to do it in react Commented Aug 18, 2017 at 7:19

1 Answer 1

4

You need to import file.json first, you can try like this :

import React, { Component } from 'react';
import { View,Text} from 'react-native';
import data  from './file.json';

export default class App extends React.Component {

  render(){
    return (
      <View>
        <Text>
          {data.children[0].children[0].value.cover.teacher}
        </Text>
      </View>
    );
  }
}

I hope this answer can help you.

Sign up to request clarification or add additional context in comments.

4 Comments

My JSON file path is : var path = RNFS.DocumentDirectoryPath + '/test.json' How to import this file?
Have you set up the configuration on the react-native-fs documentation?
From github.com/itinance/react-native-fs#basic , i think you need to use readDir(RNFS.DocumentDirectoryPath) method and return promise to read your file from your directory. I am sorry can't help you more because I have never used this library, so I need to learn about it first.
How to execute it using loop to print all the key value presented in JSON file?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.