Filter löschen
Filter löschen

Parse JSON String to Structure

87 Ansichten (letzte 30 Tage)
Michael
Michael am 8 Mai 2015
Beantwortet: Kunal Kandhari am 22 Jun. 2021
I can use webread to parse json delivered by a webservice into a struct, but is there any way to do that same parsing if I have the JSON data in a string?

Antworten (1)

Kunal Kandhari
Kunal Kandhari am 22 Jun. 2021
This can be done using :
jsondecode('string text');
For more reference:
Sample program:
myStruct=struct();
myStruct.name="Hello";
myStruct.age="21";
myStructString=jsonencode(myStruct);
fprintf("Original structure: \n");
disp(myStruct);
fprintf("Original structure converted to string: \n");
disp(myStructString);
myStruct2=struct();
myStruct2=jsondecode(myStructString);
fprintf("\n\nOriginal structure parsed back from string: \n");
disp(myStruct2);
Output:

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by