Questions tagged [jsonencoder]

Use this tag for `JSONEncoder` questions on Apple platforms.

JSONEncoder is a class, introduced in Swift 4, for encoding types on Apple operating systems that conform to Encodable protocol (or Codable protocol, which is type alias for Encodable & Decodable). This offers a simple mechanism to easily generate JSON from Encodable Swift types. This applies to standard Swift collections, such as Array and Dictionary, but custom types can conform to Encodable to participate in this simplified JSON encoding process.

This replaces/supplements the JSONSerialiation class used in prior Swift versions.

See also:

125 questions
0
votes
1 answer

Sanitize an external xml file with php

Here's my problem: function parse_xml_to_json($url) { $fileContents = file_get_contents($url); $simpleXml = simplexml_load_string($fileContents, null , LIBXML_NOCDATA); $json = json_encode($simpleXml); return $json; } $jsonto =…
0
votes
3 answers

unable to get back end array data using JSON-encode

i have a script (Users.php) that uses JSON_encode to display an array of objects in an HTML table. as in: Users.php : html //empty table script //fills the table by using json encode to get php array and display the contents in the table myPhp.php…
layla l00
  • 33
  • 1
  • 6
0
votes
0 answers

parsererror SyntaxError: Unexpected token in JSON at position 0

i'm new in web develope and now get the error in ajax.. i have a page (things.php) for get info from users and then send info via ajax to authenticate.php, and in this page call db.class.php for push and fetch data from database, now i want to fetch…
0
votes
2 answers

How to use Codable encode with object inside object

Im working on a JSON payload with my object payload. but im having trouble encoding object inside object. My Payload class was this class ConversationPayload :BaseObject { var title : String? = "" var messageDict: MessagePayload =…
Edgar
  • 179
  • 11
0
votes
1 answer

Swift - Override default encoding/decoding

CGSize is encoded to an array by default. I would like to encode it to [String: Float] (i.e. ["width": 10, "height": 20]). Is there a way to override the default encoding/decoding behavior? Of course, as a workaround, I can define my own Dimension…
Jack Guo
  • 3,959
  • 8
  • 39
  • 60
0
votes
1 answer

Swift used Codable, but the type is not correct

I know that Codable = Decodable & Encodable but when calling json from xcode, Codable was given as a struct, but an error saying Argument type'login.Type' does not conform to expected type'Encodable' appears. json code struct login: Codable { …
je2
  • 35
  • 1
  • 6
0
votes
1 answer

json response convert int to string problem laravel

I use the following command to output in Laravel : response()->json($data, $status, [])->send(); it has been converting all the numbers that are numerically defined in the database into strings Using the following value solves this problem, but…
0
votes
3 answers

Getting value of php that is json_encode

Hello im trying to get the value of an element that is json_encoded. public function getDescription($noArticle){ $stmt = $this->prepare("SELECT description FROM Inventaire WHERE noArticle = '{$noArticle}' "); $stmt->execute(); $result =…
Anasde
  • 17
  • 3
0
votes
1 answer

Unable to make POST request that inserts tokenID into the request_token field

I keep getting the same error: {"status_code":6,"status_message":"Invalid id: The pre-requisite id is invalid or not found."} The point of the code is get a token id and then use that token id to create a session id, but whenever I make the call it…
Sola
  • 25
  • 6
0
votes
1 answer

Swift JSONEncoder.dataCodingStrategy custom function not being called

I have been trying to get JSONEncoder's dataEncodingStrategy work. I need to get my http body data without escaped on API requests and there is this withoutEscapingSlashes: JSONEncoder.OutputFormatting of JSONEncoder but unfortunately this is only…
JustWork
  • 1,944
  • 3
  • 22
  • 34
0
votes
1 answer

Swift Error "Type 'BookingDataModel' does not conform to protocol 'Decodable'"

I wanted to make some part of my app offline as the my client requested it. I've been racking my brain on making my structure codable so that I can save the data to user defaults, but I always get this error Type 'BookingDataModel' does not…
Akshay
  • 167
  • 1
  • 11
0
votes
1 answer

Removing unnecessary JSON spaces

I have encoded a Codable object: let encodedData = try JSONEncoder().encode(someObject) And I print the JSON by doing the following (I know its not safe, I'm just testing): let json = try! JSONSerialization.jsonObject(with:…
George
  • 25,988
  • 10
  • 79
  • 133
0
votes
1 answer

I am getting a date of "598146673" when I use JSONEncoder with a Date type

Title says it all. I don't mind getting the date as "598146673" but I just need to convert it when I receive that on my Django. Ideally, I would like to what format it is or how I can have xcode leave it in "2019-12-15 23:51:13 +0000"
Andy Nguyen
  • 451
  • 5
  • 17
0
votes
1 answer

Log management with multiple array in json_encode

I've looked for several days, read multiple threads and i didnt find any answer. Here is my problem : i'm remaking the log management on CodeIgniter 3.XX. I collect the datas for each log message in a array like this : $log_message['date'] =…
antoinich
  • 21
  • 3
0
votes
0 answers

Php API json_encode coding not responding to MySQL query

I am trying to get a response from my api coding but it does not return any results even when the code is true Here is my code prepare('select * from users where…
1 2 3
8 9