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
1
vote
0 answers

How to encode a already encoded json data(as string) into another json in swift 4, iOS 11.3, xcode 9?

I am trying to encode a already encoded json data into another json as a string element. First I have created a json data as string with jsonEncoder, Now I have to send that json data(string) as an element of another jsonEncoder's element. So far…
Neck
  • 611
  • 1
  • 7
  • 21
1
vote
1 answer

How to make file .json with codeigniter?

This is my json encode in my controller: public function loaddata(){ $sql = $this->db->query('select * from e_alat_angkutan')->result(); return json_encode($sql); } how to make file .json ? please help
irufano
  • 108
  • 1
  • 11
1
vote
0 answers

swift JSONEncoder set element order

Is there a way to set a custom order to the elements from a JSONEncoder? For example if I have an Encodable with elements id, message, and error is there a way to make sure the JSONEncoder returns those elements in that order? Currently it seems to…
Kevin Schildhorn
  • 197
  • 2
  • 16
1
vote
1 answer

JSONSerialization serialize dictionary with wrong types

I'm having trouble translating my models into dictionaries. My models inherit from Codable and when using JSONSerialization I get a dictionary with the form: (...,"sensors": <__NSArrayI 0x1105324f0>( { accx = "-0.002471923828125"; accy =…
1
vote
1 answer

JSONEncoder strips trailing zeros

Is there a way to configure JSONEncoder to add trailing decimal mark and zero when converting Double (whole number) to JSON? Code below illustrates the issue. import Foundation struct NumberTest: Codable { let number: Double enum…
1
vote
2 answers

How to get utf-8 in json_encode php when convert from array to string?

How to get utf-8 in json_encode php when convert from array to string ? This is my code for test.php:
mamiw
  • 123
  • 4
  • 9
1
vote
2 answers

Convert JSON encoded class to dictionary for Alamofire parameters

Let's say I got the following struct public class Response: Codable { let status: String let code: String let id: String } What I want is to get the class properties and values as [String: Any] to send it through Alamofire like…
Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131
0
votes
4 answers

How can I apply a global .dateDecodingStrategy for all JSONEncoder and JSONDecoder?

I haven't found any info/similar questions here. I need to use .iso8601 for my JSONDecoder and JSONEncoder. Current I am doing this for each HTTP call: let decoder = JSONDecoder() decoder.dateDecodingStrategy =…
Zera Zinc
  • 29
  • 4
0
votes
1 answer

App crashes when trying to encode custom objects that conform to codable protocol and I can't figure out why, any thoughts?

So I have two custom objects, Exercises and Workouts. Exercises conforms to Codable and is able to be encoded and decoded just fine using JSONEncoder. I have an array of Exercise objects that I archive. The issue is with the Workout object. For some…
Chubbles
  • 123
  • 5
0
votes
1 answer

List elements should be separated by comma and space in json.dumps

I have a json which contains dictionaries, lists, integers etc. json_str = ''' { "name": "John", "age": 30, "pets": [ { "name": "Fluffy", "type": "cat", "toys": [ "ball", …
0
votes
0 answers

Load vie in ajax request CI3

I want request to load view as well as make json data availabel for sam loaded view in bellow ajax request, I am making request to dataDetail method which load views and also i want json data to be available in same loaded views, I tried following…
Djmboudz
  • 1
  • 2
0
votes
0 answers

Limit precision on JSONEncoder's Double output

I'm working on a document-based SwiftUI application, and my file contents includes large arrays of doubles. The application involves importing some data from CSV, and then the file saves this data in a data structure. However, when looking at the…
Tahmid Azam
  • 566
  • 4
  • 16
0
votes
0 answers

encoding a neural network in a json file

i am building a federated learning model, i would need to json encode my model so that i can exchange it with new workers i add to the network. could you help me? is it possible to encode a model in a json file so that it can be sent? below i put my…
0
votes
0 answers

Clickatell SMS content doesn't print + sign it become empty space , how can I solve this issue

public void sendMessageToRXCustomer(InviteCustomerSMSDto inviteCustomerSMSDto) { RestTemplate restTemplateService = new RestTemplate(); String smsServiceApiEndPoint = env.getProperty("SmsServiceApiEndPoint"); String…
0
votes
1 answer

Error with JSONEncoder when start a Python Quart application

When I start Quart without Mongo, every think is fine. But after I start to intergrated Qurat-Moto I have the following error: AttributeError: module 'quart.json' has no attribute 'JSONEncoder' I try several Python interpretor: Poetry with Python…
sebajou
  • 3
  • 2
1 2 3
8 9