简体   繁体   English

从Web服务反序列化PHP数据

[英]Deserializing PHP Data from Web service

I'm receiving data from a web service. 我正在从Web服务接收数据。 The data are in the following format: 数据采用以下格式:

a:5:{s:7:"request";s:14:"94.190.179.118";s:6:"status";i:206;s:12:"currencyCode";s:3:"BGL";}

I need to parse the input. 我需要解析输入。

Can you advise me what format is this and what is the easiest way to parse them? 你能告诉我这是什么格式以及解析它们的最简单方法是什么?

... ...

I can parse by splitting the string by ';' 我可以通过';'分割字符串来解析 and to search the individual elements for the wanted key and the following value. 并在单个元素中搜索所需的键和以下值。 (possible, but bad solution) Probably the data are serialized in a standard format and can be deserialized in a dictionary. (可能,但不好的解决方案)可能数据是以标准格式序列化的,可以在字典中反序列化。

This looks like serialized PHP: http://php.net/serialize 这看起来像序列化的PHP: http//php.net/serialize

PHP includes built in deserialize methods. PHP包含内置的反序列化方法。 As for C#, there might be 3rd library somewhere that will do this for you. 对于C#,可能会有第3个库可以为你做这个。

My advice would be to see if you can have the API communicate in a standardised format such as JSON or XML. 我的建议是看看您是否可以使用标准格式(如JSON或XML)进行API通信。 Failing that, you will need to convert it from a serialized string, to usable object data in C#. 如果做不到这一点,您需要将它从序列化字符串转换为C#中的可用对象数据。

This is PHP's own serialization format. 这是PHP自己的序列化格式。 Try Sharp Serialization Library to read this in. 尝试使用Sharp Serialization Library来阅读此内容。

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

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