Show a json file in a edit text

3 ビュー (過去 30 日間)
Andrea Simonotti
Andrea Simonotti 2019 年 1 月 6 日
回答済み: Walter Roberson 2019 年 1 月 7 日
Hi, i'm doing a project for my university.
In a part of it i need to show in a edit text a json file(i don't have to show the structure create by matlab, but only the text of the json file), for example {"Tot_ricoveri":21555,"Rimborsi":[{"Cod_drg":4,"nricoveri_drg":15,"Tot_rimborso_drg":93883.842129455079},.....
The problem is: how can i read this file?
I tryed with this:
fname1 = 'OSPEDALE6_ASL_GLUCOSIO_REGIONE2.json';
fid = fopen(fname1,'r');
fclose(fid);
set(handles.JSON,'String',fid)
But it, print 5 and not what i want.
  1 件のコメント
Rik
Rik 2019 年 1 月 6 日
Have you read the documentation? It is a great place to start.
It will tell you that the fid is a handle to a file, not its contents. You need to use any of the several functions linked at the bottom of the doc page for fopen.
You could even use the fileread function instead.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 1 月 7 日
S = regexp( fileread(fname1), '\r?\n');
set(handles.JSON, 'Max', 2, 'String', S)

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by