2016-06-01 16 views
0

私はJSON.netをリサーチベースのプロジェクトに使用しています。私のサンプルJSONファイルは次のようになります。ファイルが巨大であるが、私と一緒にクマ、私はそれの一部を処理する必要があります。基本JSON解析クエリ

{ 
    "connectionName" : "example.com", 
    "connectionPort" : 443, 
    "SNI" : "example.com", 
    "SSLv3" : { 
    "suiteSelection" : "server", 
    "suites" : [ 
     { 
     "id" : 49169, 
     "name" : "ECDHE_RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49171, 
     "name" : "ECDHE_RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49172, 
     "name" : "ECDHE_RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 47, 
     "name" : "RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 53, 
     "name" : "RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 5, 
     "name" : "RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     } 
    ] 
    }, 
    "TLSv1.0" : { 
    "suiteSelection" : "server", 
    "suites" : [ 
     { 
     "id" : 49169, 
     "name" : "ECDHE_RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49171, 
     "name" : "ECDHE_RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49172, 
     "name" : "ECDHE_RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 47, 
     "name" : "RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 53, 
     "name" : "RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 5, 
     "name" : "RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     } 
    ] 
    }, 
    "TLSv1.1" : { 
    "suiteSelection" : "server", 
    "suites" : [ 
     { 
     "id" : 49169, 
     "name" : "ECDHE_RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49171, 
     "name" : "ECDHE_RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49172, 
     "name" : "ECDHE_RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 47, 
     "name" : "RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 53, 
     "name" : "RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 5, 
     "name" : "RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     } 
    ] 
    }, 
    "TLSv1.2" : { 
    "suiteSelection" : "server", 
    "suites" : [ 
     { 
     "id" : 49199, 
     "name" : "ECDHE_RSA_WITH_AES_128_GCM_SHA256", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49191, 
     "name" : "ECDHE_RSA_WITH_AES_128_CBC_SHA256", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49169, 
     "name" : "ECDHE_RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49171, 
     "name" : "ECDHE_RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49172, 
     "name" : "ECDHE_RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49200, 
     "name" : "ECDHE_RSA_WITH_AES_256_GCM_SHA384", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 49192, 
     "name" : "ECDHE_RSA_WITH_AES_256_CBC_SHA384", 
     "strength" : 3, 
     "forwardSecrecy" : true, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 156, 
     "name" : "RSA_WITH_AES_128_GCM_SHA256", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 157, 
     "name" : "RSA_WITH_AES_256_GCM_SHA384", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 60, 
     "name" : "RSA_WITH_AES_128_CBC_SHA256", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 47, 
     "name" : "RSA_WITH_AES_128_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 61, 
     "name" : "RSA_WITH_AES_256_CBC_SHA256", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 53, 
     "name" : "RSA_WITH_AES_256_CBC_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     }, 
     { 
     "id" : 5, 
     "name" : "RSA_WITH_RC4_128_SHA", 
     "strength" : 3, 
     "forwardSecrecy" : false, 
     "anonymous" : false, 
     "serverKeyType" : "RSA" 
     } 
    ] 
    }, 
    "ssl3Chains" : [ 
    { 
     "length" : 3, 
     "decoded" : true, 
     "namesMatch" : true, 
     "includesRoot" : false, 
     "signHashes" : [ 
     "SHA-1", 
     "SHA-256" 
     ], 
     "certificates" : [ 
     { 
      "thumbprint" : "4F851C51052200FE11C8BBFA1ED4BD29CFC7CB16", 
      "decodable" : true, 
      "serialHex" : "773A528C676E2348E3E6ED494D6A5EC9", 
      "subject" : "CN=www.example.cn,OU=service operation department,O=BeiJing example Netcom Science Technology Co.\\, Ltd,L=beijing,ST=beijing,C=CN", 
      "issuer" : "CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US", 
      "validFrom" : "2016-04-10 00:00:00 UTC", 
      "validTo" : "2017-04-11 23:59:59 UTC", 
      "keyType" : "RSA", 
      "keySize" : 2048, 
      "signHash" : "SHA-256", 
      "selfIssued" : false, 
      "serverNames" : [ 
      "example.cn", 
      "example.com", 
      "example.com.cn", 
      "w.example.com", 
      "ww.example.com", 
      "www.example.cn", 
      "www.example.com.cn", 
      "www.example.com.hk", 
      "www.example.hk", 
      "www.example.net.au", 
      "www.example.net.my", 
      "www.example.net.ph", 
      "www.example.net.pk", 
      "www.example.net.tw", 
      "www.example.net.vn", 
      "wwww.example.com", 
      "wwww.example.com.cn" 
      ] 
     }, 
     { 
      "thumbprint" : "FF67367C5CD4DE4AE18BCCE1D70FDABD7C866135", 
      "decodable" : true, 
      "serialHex" : "513FB9743870B73440418D30930699FF", 
      "subject" : "CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US", 
      "issuer" : "CN=VeriSign Class 3 Public Primary Certification Authority - G5,OU=(c) 2006 VeriSign\\, Inc. - For authorized use only,OU=VeriSign Trust Network,O=VeriSign\\, Inc.,C=US", 
      "validFrom" : "2013-10-31 00:00:00 UTC", 
      "validTo" : "2023-10-30 23:59:59 UTC", 
      "keyType" : "RSA", 
      "keySize" : 2048, 
      "signHash" : "SHA-256", 
      "selfIssued" : false 
     }, 
     { 
      "thumbprint" : "32F30882622B87CF8856C63DB873DF0853B4DD27", 
      "decodable" : true, 
      "serialHex" : "250CE8E030612E9F2B89F7054D7CF8FD", 
      "subject" : "CN=VeriSign Class 3 Public Primary Certification Authority - G5,OU=(c) 2006 VeriSign\\, Inc. - For authorized use only,OU=VeriSign Trust Network,O=VeriSign\\, Inc.,C=US", 
      "issuer" : "OU=Class 3 Public Primary Certification Authority,O=VeriSign\\, Inc.,C=US", 
      "validFrom" : "2006-11-08 00:00:00 UTC", 
      "validTo" : "2021-11-07 23:59:59 UTC", 
      "keyType" : "RSA", 
      "keySize" : 2048, 
      "signHash" : "SHA-1", 
      "selfIssued" : false 
     } 
     ] 
    } 
    ], 
    "deflateCompress" : false, 
    "serverTime" : "random", 
    "secureRenegotiation" : true, 
    "minECSize" : 256, 
    "minECSizeExt" : 256, 
    "namedCurves" : [ 
    { 
     "name" : "secp256r1 (P-256)", 
     "size" : 256, 
     "spontaneous" : true 
    } 
    ], 
    "warnings" : [ 
    { 
     "id" : "CS005", 
     "text" : "Server supports RC4." 
    }, 
    { 
     "id" : "CS006", 
     "text" : "Server supports cipher suites with no forward secrecy." 
    }, 
    { 
     "id" : "PV003", 
     "text" : "Server supports SSL 3.0." 
    }, 
    { 
     "id" : "XC001", 
     "text" : "Server certificate was signed with a weak/deprecated/unknown hash function." 
    } 
    ] 
} 

だから私はちょうど私が簡単なCNameクラスを作成したので、出力ウィンドウにnameを印刷したいです。ここに私のコードは次のとおりです。

public class CName 
{ 
    public string name { get; set; } 
} 

DirectoryInfo dinfo = new DirectoryInfo(@"C:\output_v_2\"); 
FileInfo[] Files = dinfo.GetFiles("*.json"); 

foreach (FileInfo file in Files) 
{ 
    CName read_data = JsonConvert.DeserializeObject<CName>(File.ReadAllText(file.Name)); 
    Debug.WriteLine(read_data.name); 
} 

EDIT:JSONの私の理解は本当に悪いようです。私がしようとしているのはこれです:"name" : "ECDHE_RSA_WITH_RC4_128_SHA",とそれに類するすべての行を"name"とすると、私は得られない値のECDHE_RSA_WITH_RC4_128_SHAを必要とします。 しかし、私はすべて空白の出力です。 提案?

ありがとうございました。

+1

jsonのルートに 'name'プロパティはありません。 –

+0

@PaulAbbott私はこれに新しいです、どうすれば 'name'にアクセスできますか? –

+0

「名前」は何ですか? @ PaulAbbottがあなたのjsonオブジェクトに "name"プロパティがないと言っています。 – Gusman

答えて

0

フルモデルを作成したくない場合は、DeserializeObject<T>()の代わりにDeserializeObject()を使用すると、必要な機能を持つオブジェクトであるJTokenが返されます配列のようなメンバーにアクセスします。

Hereは、JTokenのドキュメントへのリンクです。