We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug JSONEncoder encodes Dictionary key as JSON value if Dictionary key is Double, works as intended with String or Int
To Reproduce Compile this code:
//Dictionary Key is Type String var Key_String : [String:Dictionary<String, Int>] = ["1":["longitude":43,"latitude":53]] do { let encodedDictionary = try JSONEncoder().encode(Key_String) let jsonString = String(data: encodedDictionary, encoding: .utf8)! print("Key_String",jsonString) //{"1":{"longitude":43,"latitude":53}} } catch { print("Error: ", error) } //Dictionary Key is Type Double let Key_Double : [Double:Dictionary<String, Int>] = [1.0:["longitude":43,"latitude":53]] do { let encodedDictionary = try JSONEncoder().encode(Key_Double) let jsonString = String(data: encodedDictionary, encoding: .utf8)! print("Key_Double",jsonString) //[1,{"longitude":43,"latitude":53}] } catch { print("Error: ", error) } //Dictionary Key is Type Int let Key_Int : [Int:Dictionary<String, Int>] = [1:["longitude":43,"latitude":53]] do { let encodedDictionary = try JSONEncoder().encode(Key_Int) let jsonString = String(data: encodedDictionary, encoding: .utf8)! print("Key_Int ",jsonString) //{"1":{"longitude":43,"latitude":53}} } catch { print("Error: ", error) }
Expected behavior JSONEncoder should encode Dictionary Key as Key
Screenshots
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
JSONEncoder encodes Dictionary key as JSON value if Dictionary key is Double, works as intended with String or Int
To Reproduce
Compile this code:
Expected behavior
JSONEncoder should encode Dictionary Key as Key
Screenshots
![image](https://user-images.githubusercontent.com/12225067/174920062-5f0db2a9-f058-4b15-8f06-10cb7e6b6334.png)
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: