2012-04-30 2 views
1

applicationDataDirectory에 저장된 로컬 JSON 파일을 구문 분석하려고합니다. 이 파일에서 항목을 가져올 필요가 있습니다. 티타늄티타늄 - 로컬 JSON 파일을 구문 분석 할 수 없습니다.

의 실행 V.2는 JSON 데이터 구조는 파일을 구문 분석하여이

{ 
"object_name": [ 
    { 
     "title": "Burrton", 
     "value": "Burrton", 
     "homeof": "Chargers", 
     "logo": "images/logos/BURRTON.jpg", 
     "colors": "#cccccc;#a9a9a9", 
     "links": { 
      "tsr": "http://www.schurzdigital.com/mfeeds/CollectionFeed.php?site=http%3A%2F%2Fwww.catchitkansas.com&collection=cik_burrton_headlines&title=cik_burrton_headlines&limit=25", 
      "sports": "www.schurzdigital.com/mfeeds/CollectionFeed.php?site=http%3A%2F%2Fwww.catchitkansas.com&collection=cik_burden_headlines&title=cik_burden_headlines&limit=25", 
      "videos": "http://www.schurzdigital.com/mfeeds/TividFeedConvert.php?site=http%3A%2F%2Fwww.catchitkansas.com&slug=e9c0b075-3230-4a45-803e-7ccb4b7f754e&title=Top%20videos&limit=25", 
      "photos": "http://serve.a-feed.com/service/getFeed.kickAction?feedId=1014509&as=8768", 
      "stats": { 
       "boys": { 
        "football": "http://stats.catchitkansas.com/report_fb-schedule_results.php?sport=15&team=763", 
        "basketball": "http://stats.catchitkansas.com/report_baskb-schedule_results.php?sport=26&team=2946", 
        "cross country": "http://stats.catchitkansas.com/report_cc-schedule_results.php?sport=13&team=764", 
        "golf": "http://stats.catchitkansas.com/report_golf-schedule_results.php?sport=16&team=767", 
        "track": "http://stats.catchitkansas.com/report_trackfield-schedule_results.php?sport=32&team=2948" 
       }, 
       "girls": { 
        "volleyball": "http://stats.catchitkansas.com/report_vb-schedule_results.php?sport=22&team=766", 
        "basketball": "http://stats.catchitkansas.com/report_baskb-schedule_results.php?sport=27&team=2947", 
        "cross country": "http://stats.catchitkansas.com/report_cc-schedule_results.php?sport=13&team=764", 
        "golf": "http://stats.catchitkansas.com/report_golf-schedule_results.php?sport=17&team=768", 
        "track": "http://stats.catchitkansas.com/report_trackfield-schedule_results.php?sport=32&team=2948" 
       } 
      } 
     } 
    } 
] 
} 

강령 메신저처럼 보인다.

var fileName = 'school_select.json'; 
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, fileName); 

if (file.exists()) { 
    var json = file.read(); 
    var jsonObject = JSON.parse(json); 

    one.text = jsonObject.object_name[0].title; 
    two.text = jsonObject.object_name[0].homeof; 
} 

답변

5

나는 내 자신의 질문에 대답했다. 다음 코드를 사용했습니다.

var fileName = 'school_select.json'; 
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, fileName);  
var json, object_name, locatie, i, row, title, value, homeof, logo, colors, link; 
var preParseData = (file.read().text); 
var response = JSON.parse(preParseData); 
    Ti.API.info('title = ' + response.object_name[0].title); 
+0

합금은 어떨까요? Alloy에서 FileSystem을 사용하여 파일에 액세스하는 방법은 무엇입니까? –

관련 문제