Skip to content

Commit b2055ff

Browse files
committed
fix: responseText handling for json
1 parent 71d38a0 commit b2055ff

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/http/http.ios.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,15 @@ class NSURLSessionTaskDelegateImpl extends NSObject
280280
}
281281

282282
let content;
283+
let responseText;
283284
if (isTextContentType(returnType)) {
284-
content = NSDataToString(this._data);
285+
responseText = NSDataToString(this._data);
286+
content = NSDataToString(responseText);
285287
} else if (returnType.indexOf('application/json') > -1) {
286288
// @ts-ignore
287-
content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
289+
responseText = NSDataToString(this._data);
290+
content = JSON.parse(responseText);
291+
// content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
288292
} else {
289293
content = this._data;
290294
}
@@ -308,6 +312,7 @@ class NSURLSessionTaskDelegateImpl extends NSObject
308312
this._resolve({
309313
url: this._url,
310314
content,
315+
responseText,
311316
statusCode: this._statusCode,
312317
headers: headers
313318
});

src/xhr/TNSXMLHttpRequest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ export class TNSXMLHttpRequest {
429429
this._response = JSON.parse(this.responseText);
430430
} else if (typeof res.content === 'object') {
431431
this._response = res.content;
432+
this._responseText = res.responseText;
432433
} else {
433434
if (isIOS) {
434435
if (res.content instanceof NSData) {

0 commit comments

Comments
 (0)