reactjs - Get the value from the JSON file using React Native -
i have json file in documentdirectorypath, json file looks
{ "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 , 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 need print key https://origin-dashboard.com/cdn/prodstore/epic_app/packets.zip
, how key above json
you need import file.json
first, can try :
import react, { component } 'react'; import { view,text} 'react-native'; import data './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 answer can you.
Comments
Post a Comment