2013-06-03 39 views
-4

以下是从文本文件中读取并存储在变量中的json元素。即访问存储在变量中的json元素

sCurrentLine = { 
    "description": "Update gclient to handle when a DEPS file has no deps dictionary.\n\nCommitted: http://src.chromium.org/viewvc/chrome?view=rev&revision=1652", 
    "cc": [], 
    "reviewers": [ 
     "[email protected]" 
    ], 
    "owner_email": "[email protected]", 
    "private": false, 
    "base_url": "svn://chrome-svn.corp.google.com/chrome/trunk/depot_tools/", 
    "owner": "sguireknight", 
    "subject": "Handle when a DEPS file has no deps dictionary.", 
    "created": "2008-09-02 20:11:04.145884", 
    "patchsets": [ 
     1 
    ], 
    "modified": "2011-05-09 13:10:20.276741", 
    "closed": true, 
    "commit": false, 
    "issue": 201 
} 

我想访问问题值201.我该怎么做?

+2

方式? – qJake

+0

嗨新用户你搜索过,还是你尝试过?检查http://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it?rq=1 – ncm

回答

1

如果你使用Javascript(没有指定),你可以只是这样做访问值:

sCurrentLine.issue 

就是这样。

+1

巧合的是,一旦适当的解析,这将是在许多语言相同的答案已完成... –

+0

@dystroy确实如此。 – qJake

0

只是为了完整性的缘故,有什么是您使用的编程语言的另一个访问它在JavaScript

sCurrentLine["issue"]