Skip to content

Commit

Permalink
Merge pull request #130 from javad-zobeidi/dev
Browse files Browse the repository at this point in the history
fix nested json (#128)
  • Loading branch information
javad-zobeidi authored Sep 22, 2024
2 parents af5a4d6 + 41dc543 commit 7262956
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/src/http/request/request.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:vania/src/exception/validation_exception.dart';
import 'package:vania/src/http/request/request_body.dart';
Expand Down Expand Up @@ -150,6 +151,18 @@ class Request {
return requestItems;
}

Map json(String key) {
if (_all[key] != null && _all[key] is String) {
return jsonDecode(_all[key]);
}

if (_all[key] != null && _all[key] is Map) {
return _all[key];
}

return {};
}

dynamic input([String? key, dynamic defaultVal]) {
if (key == null) {
return _all;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/http/request/request_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import 'dart:io';
import 'package:vania/src/http/request/request_form_data.dart';

String _fixJsonString(String jsonString) {
return jsonString.replaceAllMapped(RegExp(r'("\w+": )(\d+)([\s,}])'),
(Match match) => '${match[1]}"${match[2]}"${match[3]}');
return jsonString.replaceAllMapped(
RegExp(r'("\w+":)\s*(\d+|\d+\.\d+)([\s,}])'),
(Match match) => '${match[1]}${match[2]}${match[3]}');
}

class RequestBody {
Expand Down

0 comments on commit 7262956

Please sign in to comment.