Coder Social home page Coder Social logo

Comments (3)

xuyecan avatar xuyecan commented on May 5, 2024

观察到,在第一步print(requestStr!)时,控制台输出:

{"body":"{"body":"123"}","name":"name"}

这不是一个合法的JSON字符表达(可在 bejson 等工具上测试),所以尝试反序列化失败。

原因是这样:var body: String = "{\"body\":\"123\"}"这个赋值,在程序运行时,程序可见的body的值是{"body": "123"}(转义已经被解释),序列化之后得到{"body":"{"body":"123"}","name":"name"},这是一个合法的字符串,却不是一个合法的JSON。

所以如果赋值为:

var body: String = "{\\\"body\\\":\\\"123\\\"}"

运行将得到正确的结果。

很抱歉,现在异常处理还不够完善,没有用合理的log来提示异常。我会尽快改进。

from handyjson.

ccxdd avatar ccxdd commented on May 5, 2024

确实是这样,我现在是通过

body.replacingOccurrences(of: "\"", with: "\\\"")

临时解决的。自己也从HandyJSON上学到很多,希望能越来好用

from handyjson.

xuyecan avatar xuyecan commented on May 5, 2024

嗯,欢迎你多多提意见,我会尽力改进的~

from handyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.