Correctly Parsing JSON in Swift 3

First of all never load data synchronously from a remote URL, use always asynchronous methods like URLSession. ‘Any’ has no subscript members occurs because the compiler has no idea of what type the intermediate objects are (for example currently in [“currently”]![“temperature”]) and since you are using Foundation collection types like NSDictionary the compiler has no … Read more

How do I POST JSON data with cURL?

You need to set your content-type to application/json. But -d (or –data) sends the Content-Type application/x-www-form-urlencoded, which is not accepted on Spring’s side. Looking at the curl man page, I think you can use -H (or –header): -H “Content-Type: application/json” Full example: curl –header “Content-Type: application/json” \ –request POST \ –data ‘{“username”:”xyz”,”password”:”xyz”}’ \ http://localhost:3000/api/login (-H … Read more

Create JSON from a String

In JavaScript: An object literal, which uses the {} syntax, consists of a collection of property: value pairs. An array literal, which uses the [] syntax, consists of a collection of values. [begin: “test1”, end: “test2”] You have used the array syntax here, but have tried to put property: value pairs inside it. This causes … Read more