-1
Ich habe die URLWie json von webservice bekommen
http://dev.nsol.sg/projects/sneakers/Api/get_all_news
Method: POST
Erforderliche Parameter:
userid
Antwort:
success = 0 (error), 1 (success)
message = Description of result if success = 0 then message will have the detail description
data: if success = 1 then we will have complete details of common requirements like All news
newsurl: News Image URL + Concatenate Value of img from DB
Hier ist mein Versuch json von URL zu holen
func news(userid:Int)
{
let post_data: NSDictionary = NSMutableDictionary()
post_data.setValue(userid, forKey: "userid")
let url:URL = URL(string: news_url)!
let session = URLSession.shared
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData
var paramString = ""
for (key, value) in post_data
{
paramString = paramString + (key as! String)
}
request.httpBody = paramString.data(using: String.Encoding.utf8)
let task = session.dataTask(with: request as URLRequest, completionHandler: {
(
data, response, error) in
guard let _:Data = data, let _:URLResponse = response , error == nil else {
return
}
let json: Any?
do
{
json = try JSONSerialization.jsonObject(with: data!, options: [])
print("abcnews")
print(json)
}
catch
{
return
}
guard let server_response = json as? NSDictionary else
{
return
}
})
task.resume()
}
Die Ausgabe von json ist
Optional({
data = (
);
message = "Invalid User id";
success = 0;
})
Wie die gültige Json zu bekommen? Sie können das Projekt von diesem Link herunterladen https://drive.google.com/file/d/1YJvAEGbh33eHBIJwt1eLOcuCiJknwY8b/view?usp=sharing
'message = "Ungültige Benutzer-ID"' ist das Problem hier. –