Closed simonkimi closed 3 years ago
same issue for me ...
OK, but you can't use
r''<post tag="\\m/"/>';
as your input test string, this package has its data passed to it in Dart string form from the xml package, not as a raw string, if you supply the string not in its raw format -
<post tag="\m/"/>
You get '{"post": {"tag": "m/"}}' which is valid json, if you double escape it -
<post tag="\\m/"/>
you get '{"post": {"tag": "\m/"}}' which is also valid json.
I'm not sure what you want this package to do here if it can't be supplied with the raw string from the xml package.
The XML I tested came from https://safebooru.org/index.php?page=dapi&s=post&q=index&tags=%20m/
Please try the following code:
import 'dart:convert';
import 'dart:io';
import 'package:xml2json/xml2json.dart';
void main() async {
final uri = Uri.parse('https://safebooru.org/index.php?page=dapi&s=post&q=index&tags=%20m/');
final httpClient = HttpClient();
final req = await httpClient.getUrl(uri);
final rsp = await req.close();
final xml = await rsp.transform(utf8.decoder).join();
final xml2json = Xml2Json()..parse(xml);
final data = xml2json.toGData();
jsonDecode(data);
}
Failed here
Unhandled exception:
FormatException: Unrecognized string escape (at character 471)
...0e.jpg", "rating": "s", "tags": " \m/ blush breasts erect_nipples finger...
^
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5)
#1 _ChunkedJsonParser.parseStringEscape (dart:convert-patch/convert_patch.dart:1184:9)
#2 _ChunkedJsonParser.parseStringToBuffer (dart:convert-patch/convert_patch.dart:1123:18)
#3 _ChunkedJsonParser.parseString (dart:convert-patch/convert_patch.dart:1038:16)
#4 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:859:22)
#5 _parseJson (dart:convert-patch/convert_patch.dart:40:10)
#6 JsonDecoder.convert (dart:convert/json.dart:505:36)
#7 JsonCodec.decode (dart:convert/json.dart:156:41)
#8 jsonDecode (dart:convert/json.dart:96:10)
#9 main (file:///F:/dart/test/main.dart:14:3)
<asynchronous suspension>
#10 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
Thanks for the test, this should now be fixed and we shouldn't now be generating invalid json, package released at version 5.0.0
Hello Steve Hamblett In this test:
Failed here
I expected that
\m/
in xml should be escaped in the json output as\\\\m/
, but got\\m/
, So a subsequent jsonDecode() will fail atRunning on
xml2json: ^4.4.0