Skip to content

Float parsing error  #113

@Przemyslaw-Wosko

Description

@Przemyslaw-Wosko

Hi,
I have troubles with parsing simple values, like Float,

i wrote simple test:

{
    "floatArray": [9.123, 0.000001, 0.1, -2]
}
func testParseFloatArray() {
        guard let path = Bundle(for: type(of: self)).path(forResource: "FloatArray", ofType: "json"),
            let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
            let json = try? JSONParser.JSONObjectWithData(data) else {
                XCTFail("Error parsing FloatArray.json")
                return
        }
        
        do {
            let array: [Float] = try json.value(for: "floatArray")
            XCTAssert(array.count == 5)
            XCTAssert(array[0] == 9.123)
        } catch {
            XCTFail(String(describing: error))
        }
    }

and it fails with:

▿ Type mismatch. Expected type Float for key: floatArray. Got '__NSCFNumber'
  ▿ typeMismatchWithKey : 3 elements
    - key : "floatArray"
    - expected : Swift.Float
    - actual : __NSCFNumber

Should i try to make pull request with fix for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions