2017-02-05 12 views
0

私は以下の入力文字列からすべてのマッチした部分文字列を見つけようとしています:Pythonでjson型の文字列に一致する部分文字列リストを取得する方法は?

{ 
    covAnalyzeArgs : [ 
    "--disable-default",   
    "-co", 
    "UNINIT_FOR_MISRA:enable_write_context:yes" 
    ], 
    fileOptions : [ 
    { 
     optionName : "misra-config", 
     fileContents : "{\n version : \"2.0\",\n standard : \"c2012\",\n title: \"Covererd\",\n deviations : [\n\n{ deviation: \"Directive 4.3\", reason: \"This rule is currently disabled in the analysis configuration.\" },\n{ deviation: \"Directive 4.4\", reason: \"This rule is currently disabled in the analysis configuration.\" },\n{ deviation: \"Rule 21.12\", reason: \"This rule is currently disabled in the analysis configuration.\" },\n{ deviation: \"Rule 22.3\", reason: \"This rule is currently disabled in the analysis configuration.\" }\n\t\t\n ]\n}\n" 
    } 
    ], 
    fileCheckerOptions : [ 
    { 
     checkerName : "PW.*_FOR_MISRA", 
     optionName : "config_file", 
     fileContents : "// Level 1\nchk \"PW.SET_BUT_NOT_USED\": on;\nchk \"PW.TRIGRAPH_IGNORED\": on;\nchk \"SW.SYM_NOT_A_TEMPLATE\": off;\n" 
    } 
    ] 
} 

私は、この文字列は「JSONデータ」に非常に似ており、私が知りたいことなどのディレクティブとルール番号のリストであることを考えます'指令4.3'または '規則22.3'。私は、オブジェクトをJSONにひそかしようとすると しかし、それはあなたが私にJSONデータにそれを転化する方法を知っているようでした

decoded = json.loads(input_string) 

を失敗しましたか? また、ディレクティブとルール番号を抽出する考えもありますか?

+0

あなたのJSONは無効です。 –

+0

これはjavascriptオブジェクトのようです。これを確認してください:http://stackoverflow.com/questions/24027589/how-to-convert-raw-javascript-object-to-python-dictionary – MYGz

答えて

0

ロードしようとしているjsonが有効なjsonではありません。キー名は二重引用符で囲む必要があります。

"version": "2.0"

ない

version: "2.0"

関連する問題