小编bbs*_*had的帖子

在键值未知时反序列化JSON

如何在C#中使用JSON.net反序列化JSON,其中键值未知(它们是多个设备的MAC地址).可能有一个或多个密钥条目.

{
    "devices":
    {
        "00-00-00-00-00-00-00-00":
        {
            "name":"xxx",
            "type":"xxx",
            "hardwareRevision":"1.0",
            "id":"00-00-00-00-00-00-00-00"
        },
        "01-01-01-01-01-01-01-01":
        {
            "name":"xxx",
            "type":"xxx",
            "hardwareRevision":"1.0",
            "id":"01-01-01-01-01-01-01-01"
        },
      }
}
Run Code Online (Sandbox Code Playgroud)

c# json json.net

3
推荐指数
1
解决办法
2763
查看次数

使用加密资源尝试/捕获/最后

我的网站上有以下代码.它将URL查询作为名为commandencrypted的字符串.我有一个try/catch/finally块,将加密的命令复制到一个MemoryStream,然后解密回一个字符串.如果发生在try块中的任何错误,他们在catch块处理.不过,我要确保所使用的任何资源finally块中被关闭.当提供无效的URL查询命令,我收到一个异常,而试图关闭csencryptedcommand CryptoStream的.例外细节遵循代码.

    // Resources used for storing and decrypting the encrypted client command
    MemoryStream msencryptedcommand = null;
    RijndaelManaged rmencryptedcommand = null;
    CryptoStream csencryptedcommand = null;
    StreamReader srdecryptedcommand = null;
    MemoryStream msdecryptedcommand = null;

    try
    {
        // Copy the encrypted client command (where two characters represent a byte) to a memorystream
        msencryptedcommand = new MemoryStream();
        for (int i = 0; i < encryptedcommand.Length; )
        {
            msencryptedcommand.WriteByte(Byte.Parse(encryptedcommand.Substring(i, 2), NumberStyles.HexNumber));
            i = i + 2;
        }
        msencryptedcommand.Flush();
        msencryptedcommand.Position = 0;

        // Define parameters …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net encryption try-catch

2
推荐指数
1
解决办法
1073
查看次数

标签 统计

c# ×2

.net ×1

asp.net ×1

encryption ×1

json ×1

json.net ×1

try-catch ×1