Just lately, I’ve began working by myself PET undertaking in iOS.
The duty that I’ve at hand is as follows:
- Serialize object into JSON utilizing JSONEncoder
- Ship that JSON to server (Spring Boot)
- Obtain the response from that server
- and many others. and many others.
I’m utilizing a normal JSONEncoder with couple of settings (see beneath):
JSON Encoding half
// Serializing it to the JSON
let jsonEncoder = JSONEncoder()
jsonEncoder.outputFormatting = .withoutEscapingSlashes
jsonEncoder.dataEncodingStrategy = .deferredToData
self.outSyncPackage = strive jsonEncoder.encode(outSyncPackageObj)
let jsonStringToBeDelivered = String(information: self.outSyncPackage!, encoding: .utf8)
As per screenshot beneath, you may see that there aren’t any points there:
Encoded JSON Textual content
Then, I’m making a URLRequest, to be able to ship that JSON to the server:
Preparation of the URLRequest object for execution
self.urlRequest?.httpMethod = "POST"
self.urlRequest?.setValue("software/json", forHTTPHeaderField: "settle for")
// self.urlRequest?.setValue("gzip", forHTTPHeaderField: "Content material-Encoding")
self.urlRequest?.setValue(self.sessionId, forHTTPHeaderField: "sessionId")
self.urlRequest?.setValue(String(self.lastSyncDate), forHTTPHeaderField: "lastSyncDateTime")
self.urlRequest?.setValue(self.purchaseKey, forHTTPHeaderField: "subCode")
// Physique
self.urlRequest?.httpBodyStream = InputStream(information: self.outSyncPackage!)
On the server facet I count on the identical JSON, with escape characters or not.
Nevertheless, upon execution of this routine I get rubbish on the server facet as enter JSON:
Final result of the UrlRequest on the server facet
Can anyone, please, clarify to me what’s it that I’m doing improper and why JSON is scrambled upon receipt?
Precise Outcome:
%7Bpercent22accountCurrencyEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22transactionTemplateEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22serverRequestedReSyncpercent22percent3Afalsepercent2Cpercent22currencyEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22categoryEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22webServerConfigurationEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22transactionEntitiespercent22percent3Apercent5Bpercent5Dpercent2Cpercent22accountEntitiespercent22percent3Apercent5Bpercent5Dpercent7D=
Anticipated Outcome:
{"accountCurrencyEntities":[],"transactionTemplateEntities":[],"serverRequestedReSync":false,"currencyEntities":[],"categoryEntities":[],"webServerConfigurationEntities":[],"transactionEntities":[],"accountEntities":[]}
PS. I attempted numerous methods of decoding that resultant string, and I discovered, that the textual content is definitely ‘HTTP URLed’ one way or the other (see the ŠŠ¾Š“ŠøŃŠ¾Š²Š°Š½ŠøŠµ URL part on the screenshot):
Varied encodings, together with HTML Escape
OnePlus 12R (Iron Gray, 16GB RAM, 256GB Storage)
ā¹45,999.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)OnePlus Nord CE 3 Lite 5G (Chromatic Gray, 8GB RAM, 128GB Storage)
ā¹17,999.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)boAt Airdopes 91 in Ear TWS Earbuds with 45 hrs Playtime, Beast Mode with 50 ms Low Latency, Dual Mics with ENx, ASAP Charge, IWP Tech, IPX4 & Bluetooth v5.3(Starry Blue)
ā¹899.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)realme Buds T300 Truly Wireless in-Ear Earbuds with 30dB ANC, 360Ā° Spatial Audio Effect, 12.4mm Dynamic Bass Boost Driver with Dolby Atmos Support, Upto 40Hrs Battery and Fast Charging (Dome Green)
ā¹2,099.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)boAt Nirvana Ion TWS Earbuds with 120 HRS Playback(24hrs/Charge), Crystal Bionic Sound with Dual EQ Modes, Quad Mics ENxā¢ Technology, Low Latency(60ms), in Ear Detection(Charcoal Black)
ā¹1,698.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Lapster 24pcs Mix Spiral Charger Spiral Charger Cable Protectors for Wires Data Cable Saver Charging Cord Protective Cable Cover
ā¹99.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Toysbuddy Re-Writable LCD Writing Tablet Pad with Screen 21.5cm (8.5Inch) for Drawing, Playing, Handwriting Best Birthday Gifts for Adults & Kids Girls Boys, Multicolor
ā¹139.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Portronics Konnect L 1.2M POR-1401 Fast Charging 3A 8 Pin USB Cable with Charge & Sync Function (White)
ā¹129.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)FUR JADEN Anti Theft Number Lock Backpack Bag with 15.6 Inch Laptop Compartment, USB Charging Port & Organizer Pocket for Men Women Boys Girls
ā¹649.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)HP X1000 Wired USB Mouse with 3 Handy Buttons, Fast-Moving Scroll Wheel and Optical Sensor works on most Surfaces, 3 years warranty
ā¹279.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Auto Amazon Links: No products found.