c# - Basic JSON Parsing Query -
so using json.net research based project. sample json file looks this. file huge bear me, need process 1 part of it:
{ "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. - 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. - 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 no forward secrecy." }, { "id" : "pv003", "text" : "server supports ssl 3.0." }, { "id" : "xc001", "text" : "server certificate signed weak/deprecated/unknown hash function." } ] }
so want print name
output window created simple cname
class. here code:
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: seems understanding of json poor. trying this: "name" : "ecdhe_rsa_with_rc4_128_sha",
, similar lines "name"
, need ecdhe_rsa_with_rc4_128_sha
type values fail get. blank output. suggestions?
thanks.
if want small part of content , don't want create full model, can use deserializeobject()
instead of deserializeobject<t>()
, return jtoken object needed functions iterate on it, access it's members arrays, etc.
here link documentation of jtoken.