繁体   English   中英

C#JSON导入:无法将字符串转换为字节数组

[英]C# JSON import: could not convert string to byte array

我已经开发了一个应用程序,可以从JSON文件导入数据。

这是我用来反序列化JSON的代码:

var json_serializer = new JavaScriptSerializer();
var json_tpp = json.tpp;
ThermalPowerPlant tpp = json_serializer.Deserialize<ThermalPowerPlant>(json_tpp);

一切工作正常,但最近我修改了ThermalPowerPlant类,以包含一个保存为字节数组的PDF。

因此,现在,我的JSON包含此字段,如果我尝试再次导入它,应用程序将返回一个异常,该异常表明它无法将String类型转换为Byte Array

我该如何处理?

编辑

这是我的JSON中的字节数组字段:

"Map": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9MZW5ndGggNTU1My9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQp4nJ1d23IcN5J951dU7JPmgeW6X/atR2xreoMi6WZbMeE3jkx7uUGwZYqeifDXL1CFS2YCmSgpHA4xC+dUnkQB2aebxeo/Lv5+uminop/64vTrRVVcTk1Zt/bnppvKarBB3XTlAtqfLn66+GP5vyn+Rw99uKj1yH/0T+a/4wd9wnLs9Tm7sukL5cJ+1qjni3sGvQyri2Y2wywYDnvwmohHEyEBntDezG0gLAEvpfVC+q4q65rHovEAZ4VjgIKqGN19V5cDYLiYVwTG1cXQzWU983A0HuBsARigiDymhqGvygGQXMyKguPqYqpaw2PhaDzA2RowQBF5TA1uNU9hvbUtkwCN+9XMwtF42CmTtE+ADAvk1vwCXX4SBLQhfVfraRwFNAYEQlowGFVeEKO3a+qyclgX8DoQIFx3loABYF0lhYNRBZXJ66OtzT/+2uhzDK2wRNZxf81ZOBoPK2pJJqwoLCbAubXiCEsgiGmDFHd9WTQGgPXFiccABZVl1o1juJjXhAChb7MEDAgEtggMUERiptc7kosFWRAQ2jdLwIBAYOvAAEUkZvq9I7mYl4UAYWeyBAwAe5+rAwMUkejqMP//ZKxTvfDqoltZg16RU3FSFz/8WBdzcfrt4t3d8fbueNifdsfD7X//7fR/nlLXXTkOgFMVp8+a2Fh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MDAwMDA1ODUwIDAwMDAwIG4gCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwNTkzOCAwMDAwMCBuIAowMDAwMDA1NjM2IDAwMDAwIG4gCjAwMDAwMDU5ODkgMDAwMDAgbiAKMDAwMDAwNjAzNCAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgOC9Sb290IDYgMCBSL0luZm8gNyAwIFIvSUQgWzxmNzAwMjI5ZDUxNzljNDZlNzNiMTFlZThiNTc0NmUxMj48ZjcwMDIyOWQ1MTc5YzQ2ZTczYjExZWU4YjU3NDZlMTI+XT4+CiVpVGV4dC01LjUuOApzdGFydHhyZWYKNjE5NgolJUVPRgo="

PS:我还检查了我的JSON,它的格式正确。

您的字段是Base64。 您需要将您的属性定义为字符串(因为它一个字符串,即使它代表字节数组也是如此)。

然后,您可以像这样转换它:

var myArr = Convert.FromBase64String(tpp.map);

JSON.NET替换JavaScriptSerializer ,此代码可完美运行:

class Program
{
    public class SomeClass
    {
        public string SomeProperty { get; set; }

        public byte[] ByteArrayProperty { get; set; }
    }



    static void Main()
    {
        SomeClass sc = new SomeClass()
        {
            SomeProperty = "la la la",
            ByteArrayProperty = new byte[] {1, 2, 3}
        };

        string json = JsonConvert.SerializeObject(sc);

        SomeClass newSC = JsonConvert.DeserializeObject<SomeClass>(json);

    }
}

编辑

json = "{\"SomeProperty\":\"la la la\",\"ByteArrayProperty\":\"JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9MZW5ndGggNTU1My9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQp4nJ1d23IcN5J951dU7JPmgeW6X/atR2xreoMi6WZbMeE3jkx7uUGwZYqeifDXL1CFS2YCmSgpHA4xC+dUnkQB2aebxeo/Lv5+uminop/64vTrRVVcTk1Zt/bnppvKarBB3XTlAtqfLn66+GP5vyn+Rw99uKj1yH/0T+a/4wd9wnLs9Tm7sukL5cJ+1qjni3sGvQyri2Y2wywYDnvwmohHEyEBntDezG0gLAEvp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Pj4KZW5kb2JqCjQgMCBvYmoKPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbNSAwIFJdPj4KZW5kb2JqCjYgMCBvYmoKPDwvVHlwZS9DYXRhbG9nL1BhZ2VzIDQgMCBSPj4KZW5kb2JqCjcgMCBvYmoKPDwvUHJvZHVjZXIoaVRleHRTaGFycJIgNS41LjggqTIwMDAtMjAxNSBpVGV4dCBHcm91cCBOViBcKEFHUEwtdmVyc2lvblwpKS9DcmVhdGlvbkRhdGUoRDoyMDE2MDQxMTEzMDAwOCswMCcwMCcpL01vZERhdGUoRDoyMDE2MDQxMTEzMDAwOCswMCcwMCcpPj4KZW5kb2JqCnhyZWYKMCA4CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwNTc1NyAwMDAwMCBuIAowMDAwMDA1ODUwIDAwMDAwIG4gCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwNTkzOCAwMDAwMCBuIAowMDAwMDA1NjM2IDAwMDAwIG4gCjAwMDAwMDU5ODkgMDAwMDAgbiAKMDAwMDAwNjAzNCAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgOC9Sb290IDYgMCBSL0luZm8gNyAwIFIvSUQgWzxmNzAwMjI5ZDUxNzljNDZlNzNiMTFlZThiNTc0NmUxMj48ZjcwMDIyOWQ1MTc5YzQ2ZTczYjExZWU4YjU3NDZlMTI+XT4+CiVpVGV4dC01LjUuOApzdGFydHhyZWYKNjE5NgolJUVPRgo=\"}";

newSC = JsonConvert.DeserializeObject<SomeClass>(json);

完美运作。 ByteArrayProperty填充有字节,没有错误。

在(例如)将JSON反序列化为抽象类上尝试接受的解决方案

提出的问题来自另一个问题,但是也许您需要为JsonSerializerSettings指定一个TypeNameHandling,以便在字符串和字节数组之间产生区别。 那里的代码有趣的摘录(适应您的问题):

....
var jset = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All };
ThermalPowerPlant tpp = ...;
string json = JsonConvert.SerializeObject(tpp, jset);
....

ThermalPowerPlant tpp2 = (ThermalPowerPlant)JsonConvert.DeserializeObject(json, jset);

没有尝试编译,也许您正在以另一种方式反序列化,所以您可能必须改进此东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM