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

issue on key order while encoding array to json

Hello i am encoding array to json so that i have created model class like below class QuotationListDataModel: Codable{ var quatation_id: String? var PartNumber: String? var Description: String? var Quantity: String? var…
Green
  • 15
  • 7
0
votes
1 answer

How i get column while compare json encoded data in select query?

The users is json encoded $agent_id = $request->get('user'); $model = AgentPermission::select('module_category')->where('users', 'like', '%$agent_id%')->get(); I want to to show "module category" where json encoded data is present in "users"…
Nabeel Ali
  • 19
  • 5
0
votes
1 answer

Cannot read NULL variable in PHP after posting JSON array through .ajax()

I'm having a problem like many other people, being able to read a PHP array variable after having sent it through ajax() post. Ajax is succeeding and displaying the returned data, which is NULL. I have already thoroughly researched SO solutions…
0
votes
0 answers

Encode array itself of Codable objects to [String: Any]

I want to send array of Codable objects. So I've created a class which conforms to Codable protocol: class ResultAnswer: Codable { var id: Int var closed: [Int]? var open: String? init(id: Int) { self.id = id } } When I…
kkiermasz
  • 464
  • 2
  • 15
0
votes
1 answer

Swift: inner Data-typed variable was encoded via JSONEncoder. How to deserialize it properly?

Consider the next example: import Foundation class UDFrame: Codable { var data:Data init(data:Data) { self.data = data } } class Event: Codable { var name:String init(name:String) { self.name = name …
nyarian
  • 4,085
  • 1
  • 19
  • 51
0
votes
1 answer

How to Remove Double Quotes in Json Response

My Code Having Json Response Like this ["0","0","0","0","0","0","204.4"] Need Like This [ 0, 0, 0, 0, 0, 0, 204.4 ] For this I have done codeigniter $query = $this->db->query($selectQuery); $totalInvoice = array(); foreach…
0
votes
0 answers

JSON encode Data Getinto foreach

how to get foreach the belos json_encode data.. I am looking to get this data into foreach and then save into…
subbun
  • 11
  • 6
0
votes
2 answers

file_get_contents json decode showing nothing

I m using google site verification recaptcha API for my website. $json = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$response."&remoteip=".$ip); when I print echo $json; its showing proper…
Jordan
  • 39
  • 1
  • 13
0
votes
1 answer

JSON string in autocomplete key and value pair

I have an JSON string like {"Name1":"ID1","Name2":"ID2"} which I have retrieved using json_encode of PHP. How can I have an input field with Name1,Name2 in autocomplete options and once Name1 is selected, ID1 to be taken in a hidden field? I am…
Mahesh Mohan
  • 103
  • 3
  • 9
0
votes
2 answers

Alamofire JSON Encoding boolean issues?

Is there any custom encoding to encode Bool as true instead of 0 or 1 ? URLEncoding has option to change the Bool as literal or numeric. But JSONEncoding.default doesn't have that option. Is there any one who has created JSONEncoding with respect…
AtherSajjad
  • 109
  • 10
0
votes
1 answer

How to encode nested arrays with JSONEncoder

I am trying to encode four different arrays into a json format with JSONEncoder, but I am unable to convert the arrays. So, please help me out. I am using swift 4, xcode 9 for iOS 11. My arrays are: var timeCart //dynamic data as string var…
Neck
  • 611
  • 1
  • 7
  • 21
0
votes
2 answers

How to convert JSON data to HTML?

I tried to code about JSON types but I got stuck how to change array from JSON into HTML. This is what I've got from JSON: { "data": { "posts": { "edges": [ { "node": { "title": "Hello World" } …
Yosua Michael
  • 397
  • 1
  • 7
  • 24
0
votes
0 answers

not able to JSON encode an array

when trying to json_encode() an array, array not encoding my array is : $jsonData = array( 'addressId' => $addid, 'paymentMethod' => 2, 'transactionId' => $orderid ); print_r($jsonData); it prints : Array ( [addressId] =>…
user9310132
0
votes
1 answer

Custom structure using jSONEncoder

Want to encode an object into a custom structure using JSONEncoder+Encodable. struct Foo: Encodable { var name: String? var bars: [Bar]? } struct Bar: Encodable { var name: String? var value: String? } let bar1 = Bar(name: "bar1",…
justintime
  • 352
  • 3
  • 11
0
votes
0 answers

nothing happening while decoding json data

Im trying to decode the following json data, NOTE, the data has a weird attribute a '\' in front of each…
Elinoter99
  • 599
  • 1
  • 7
  • 22
1 2 3
8 9