Json Parsing error on formatted text
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joe Rustan
am 26 Mär. 2021
Beantwortet: Mohammad Sami
am 29 Mär. 2021
Hi,
I have a script that reads formatted text from a Github release description. The text has bullets, some non-ASCII characters, etc. When I look at the string, the special characters are escaped (\r, etc). When I try to write this entire text block to another Github release, it fails with an "error parsing Json" error.
I believe this has to do with either a Conten-type header or UTF encoding, which I'm not fully familiar with.
Is there a straight-forward way in Matlab to read and write formatted text "as-is"?
Thanks.
Joe
Akzeptierte Antwort
Mohammad Sami
am 29 Mär. 2021
I assume this is the api you are using.
On the documentation they show the curl request as follows.
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/releases \
-d '{"tag_name":"tag_name"}'
I believe you need to form your entire curl request as json string.
From the code I see you are missing the opening and closing {} as well as formatting of your -d argument is not json compliant
For example it should be something like this.
%curl...-d '{"tag_name":"<name-of-tag>","target_commitish":"<commit-id>","name":<name-of-release>","body":"<rel-body>"}'
Or you could can create a struct in matlab with the required parameters then use jsonencode function to form the required json string.
postdata.tag_name = name-of-tag;
postdata.target_commitish = commit-id;
postdata.name = name-of-release;
postdata.body = rel-body;
data = jsonencode(postdata);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu JSON Format finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!