• <legend id='JpVhj'><style id='JpVhj'><dir id='JpVhj'><q id='JpVhj'></q></dir></style></legend>
  • <i id='JpVhj'><tr id='JpVhj'><dt id='JpVhj'><q id='JpVhj'><span id='JpVhj'><b id='JpVhj'><form id='JpVhj'><ins id='JpVhj'></ins><ul id='JpVhj'></ul><sub id='JpVhj'></sub></form><legend id='JpVhj'></legend><bdo id='JpVhj'><pre id='JpVhj'><center id='JpVhj'></center></pre></bdo></b><th id='JpVhj'></th></span></q></dt></tr></i><div id='JpVhj'><tfoot id='JpVhj'></tfoot><dl id='JpVhj'><fieldset id='JpVhj'></fieldset></dl></div>

    • <bdo id='JpVhj'></bdo><ul id='JpVhj'></ul>

      <small id='JpVhj'></small><noframes id='JpVhj'>

      <tfoot id='JpVhj'></tfoot>

        如何反序列化包含分隔 JSON 的 JSON?

        How can I deserialize JSON containing delimited JSON?(如何反序列化包含分隔 JSON 的 JSON?)

          <tbody id='yIZXO'></tbody>
        <i id='yIZXO'><tr id='yIZXO'><dt id='yIZXO'><q id='yIZXO'><span id='yIZXO'><b id='yIZXO'><form id='yIZXO'><ins id='yIZXO'></ins><ul id='yIZXO'></ul><sub id='yIZXO'></sub></form><legend id='yIZXO'></legend><bdo id='yIZXO'><pre id='yIZXO'><center id='yIZXO'></center></pre></bdo></b><th id='yIZXO'></th></span></q></dt></tr></i><div id='yIZXO'><tfoot id='yIZXO'></tfoot><dl id='yIZXO'><fieldset id='yIZXO'></fieldset></dl></div>

        • <small id='yIZXO'></small><noframes id='yIZXO'>

            <tfoot id='yIZXO'></tfoot>
              • <bdo id='yIZXO'></bdo><ul id='yIZXO'></ul>
                <legend id='yIZXO'><style id='yIZXO'><dir id='yIZXO'><q id='yIZXO'></q></dir></style></legend>

                  本文介绍了如何反序列化包含分隔 JSON 的 JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在将 Json 字符串反序列化为对象时遇到问题.

                  I have a problem with deserializing a Json-string to an object.

                  这是我从网络服务收到的示例 json:

                  This is a sample json i receive from a webservice:

                  {
                      "GetDataResult":
                                   "{
                                       "id":1234,
                                       "cityname":"New York",
                                       "temperature":300,
                                    }"
                  }
                  

                  我有一个像这样的类 CityData

                  And I have a class CityData that looks like this

                  [JsonObject("GetDataResult")]
                  public class CityData
                  {
                      [JsonProperty("id")]
                      public int Id { get; set; }
                  
                      [JsonProperty("cityname")]
                      public string CityName { get; set; }
                  
                      [JsonProperty("temperature")]
                      public int Temperature { get; set; }
                  }
                  

                  我尝试通过调用 DeserializeObject 方法来反序列化 json

                  I try to deserialize the json with a call of the method DeserializeObject

                  var cityData = JsonConvert.DeserializeObject<CityData>(response);
                  

                  但根元素似乎有问题......

                  but the root element seems to make problems...

                  你们知道我该如何解决它,以便我收到一个填写了数据的 CityData 对象吗?

                  Do you guys know how I can fix it, so that I receive a CityData-object with the data filled in?

                  推荐答案

                  json 响应包含一个对象,该对象本身包含一个表示数据结果的 json 字符串.

                  The json response contains an object that within itself contains a json string representing the data result.

                  您需要反序列化两次,一次用于响应,一次用于数据结果.

                  You need to deserialize twice, once for the response and one more for the data result.

                  var response = JsonConvert.DeserializeObject<JObject>(responseStr);
                  var dataResult = (string)response["GetDataResult"];
                  var cityData = JsonConvert.DeserializeObject<CityData>(dataResult);
                  

                  这篇关于如何反序列化包含分隔 JSON 的 JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)
                      <tbody id='Cexzx'></tbody>

                      1. <tfoot id='Cexzx'></tfoot>
                        <legend id='Cexzx'><style id='Cexzx'><dir id='Cexzx'><q id='Cexzx'></q></dir></style></legend>
                        <i id='Cexzx'><tr id='Cexzx'><dt id='Cexzx'><q id='Cexzx'><span id='Cexzx'><b id='Cexzx'><form id='Cexzx'><ins id='Cexzx'></ins><ul id='Cexzx'></ul><sub id='Cexzx'></sub></form><legend id='Cexzx'></legend><bdo id='Cexzx'><pre id='Cexzx'><center id='Cexzx'></center></pre></bdo></b><th id='Cexzx'></th></span></q></dt></tr></i><div id='Cexzx'><tfoot id='Cexzx'></tfoot><dl id='Cexzx'><fieldset id='Cexzx'></fieldset></dl></div>

                        <small id='Cexzx'></small><noframes id='Cexzx'>

                            <bdo id='Cexzx'></bdo><ul id='Cexzx'></ul>