简体   繁体   English

序列化JSON C#中的对象列表并在Android上反序列化

[英]Serialize a list of objects in JSON C# and deserialize it on Android

I need to serialize a list of objects in JSON C# and deserialize it on Android. 我需要序列化JSON C#中的对象列表,并在Android上反序列化。

C# C#

public string SerializeData(List<SymbolsInfo> dave)
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();
        string json = jss.Serialize(dave);
        return json;
    }

Serialization -- OK. 序列化-确定 How i can to deserialize this list on android ? 我如何在Android上反序列化此列表?

[Serializable]
public partial class SymbolsInfo
{
    public string SName { get; set; }
    public Nullable<double> SPrice { get; set; }
    public Nullable<int> SVolume { get; set; }
    public System.DateTime SDate { get; set; }
}

According to my knowledge 据我所知

  • Android doesn't support auto JSON deserialisation, and the only JAVA library that I know is Jackson, check FasterXML/jackson at github, which I don't think it's suitable for your android case. Android不支持自动JSON反序列化,并且我知道的唯一JAVA库是Jackson,请在github上检查FasterXML / jackson,我认为这不适合您的android案例。

  • The common solution is to read the http response and then parse it manually using JSONOBject / JSONArray according to your response. 常见的解决方案是读取http响应,然后根据您的响应使用JSONOBject / JSONArray手动对其进行解析。 This link contains good explanation about how to use these object, check decode JSON section 此链接包含有关如何使用这些对象的详细说明, 请检查“解码JSON”部分

  • About doing the http request and current the response, android support two http client. 关于执行http请求和当前响应,android支持两个http客户端。 for more details check this link 有关更多详细信息,请检查此链接

This may help you, Use ObjectMapper class from jackson library 这可能会帮助您,使用Jackson图书馆中的ObjectMapper类

Receive data over socket and pass that string to following program 通过套接字接收数据并将该字符串传递给以下程序

jsonData="{\"StringRecivedOverTheSocket":\"OK\"}";
      ObjectMapper objectMapper = new ObjectMapper();



List<SymbolsInfo> list= objectMapper.readValue(jsonData, List<SymbolsInfo>.class);

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

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