Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8038

JSONEncoder for bool, number and string value fails

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: Foundation
    • Labels:
      None
    • Environment:

      xCode Version 9.4 (9F1027a)

      Swift 4.1

      Description

      do {

                  let encodedData = try JSONEncoder().encode(true)

              } catch {

                  print(error.localizedDescription)

              }

      the same for 

      both

       let encodedData = try JSONEncoder().encode(true)

      and 

       let encodedData = try JSONEncoder().encode("test")

      this code yeilds:

       

      The data couldn’t be written because it isn’t in the correct format.

      o_O? Why?

      Regarding the documentation 'true' is really JSON like other simple types.

      https://www.json.org/

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            trololo Vyacheslav
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: