2011-09-15 13 views
0

我有這個JSON數據。 我的問題是,是否可以在不讀取所有值的情況下提取JSON數據中的特定數據。 我的意思是有可能像我們在SQL中那樣查詢數據?是否可以提取JSON數據中的特定數據,而無需讀取所有值

{ "_id" : ObjectId("4e61501e6a73bc73f82f91f3"), "created_at" : "2011-09-02 17:52:30.285", "cust_id" : "sdtest", "moduleName" : "balances", "responses" : [ 
      { 
        "questionNum" : "1", 
        "answer" : "Hard", 
        "comments" : "is that you john wayne?" 
      }, 
      { 
        "questionNum" : "2", 
        "answer" : "Somewhat", 
        "comments" : "ARg!" 
      }, 
      { 
        "questionNum" : "3", 
        "answer" : "", 
        "comments" : "Yes" 
      } 
    ] } 

回答

0

那麼,除非你使用incremental JSON解析器,你必須首先解析整個JSON。之後,這取決於您的編程語言如何過濾的能力。例如,在Python中

import json 
obj = json.loads(jsonData) 
answeredQuestions = filter(lambda response: response.answer, obj["responses"])