Skip to content

[SR-2151] NSJSONSerialization.data(withJSONObject:options) produces illegal JSON code #4455

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-2151
Radar None
Original Reporter abinner (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 3.0 (swift-3.0-PREVIEW-2)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee DavidYangLiu (JIRA)
Priority Medium

md5: b9078e1e9b7a2c5c536f4a7d304e2f37

Issue Description:

When serializing Double values smaller than 1.0 and bigger than -1.0, the current implementation omits the leading "0". This is not allowed according to json.org and in fact the produced JSON code can't be parsed by the iOS/macOS implementation of NSJSONSerialization!

Example

Incorrect

{
    "foo": .1234
}

Should be

{
   "foo": 0.1234
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions