![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/661400/image.png)
Parse JSON String to Structure
조회 수: 78 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Kunal Kandhari
2021년 6월 22일
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/661400/image.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!