System.Text.Json.JsonException: The input does not contain any JSON tokens
Another reason this error could pop up, as it did for me, is simply because the API endpoint doesn’t exist because it was misspelled.
Another reason this error could pop up, as it did for me, is simply because the API endpoint doesn’t exist because it was misspelled.
For serializing response just use any custom attribute on action and custom contract resolver (this is only solution, unfortunately, but I’m still looking for any more elegance one). Attribute: public class ReturnValueTupleAttribute : ActionFilterAttribute { public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { var content = actionExecutedContext?.Response?.Content as ObjectContent; if (!(content?.Formatter is JsonMediaTypeFormatter)) { return; } var … Read more
In .net core the most common way of serializing and deserializing objects (JSON) using Newtonsoft.Json. You need to install the Nuget Package of Newtonsoft.Json add using a statement like: using Newtonsoft.Json; and use it as: object o = JsonConvert.DeserializeObject(json1); string json2 = JsonConvert.SerializeObject(o, Formatting.Indented);
You need to implement Do Try Catch error handling as follow: import UIKit import PlaygroundSupport PlaygroundPage.current.needsIndefiniteExecution = true extension URL { func asyncDownload(completion: @escaping (_ data: Data?, _ response: URLResponse?, _ error: Error?) -> ()) { URLSession.shared .dataTask(with: self, completionHandler: completion) .resume() } } let jsonURL = URL(string: “https://api.whitehouse.gov/v1/petitions.json?limit=100”)! let start = Date() jsonURL.asyncDownload { … Read more
Try the JavaScriptSerializer instead of the DataContractJsonSerializer JavaScriptSerializer serializer = new JavaScriptSerializer(); var output = serializer.Serialize(your_anon_object);
JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object). When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom in this format. Serialization … Read more