Highlighted
Outstanding Contributor.
Outstanding Contributor.
1196 views

Import json data

is it possible with visual to Import json-data/files simply?

Or must we have separate Tools?

have MF a Little examples in Cobol?

thanks for each help!

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Import json data

Can you please provide some more detail as to what you wish to do with the JSON files? If you wish to access a RESTful Web Service using JSON then the Interface Mapping Toolkit (IMTK) can generate a COBOL client from a JSON schema file that will consume the Web Service. Which Visual COBOL product are you using, VC Visual Studio, Eclipse or DevHub?
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Import json data

I just have developed a small WPF-Program reading a JSON file and displaying some filed in a DataGrid. I send it to Claude Greiner.
0 Likes
Highlighted
Super Contributor.
Super Contributor.

RE: Import json data

You could make it available to the community. I also have an interest in this subject. Thank you!
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Import json data

*> Author: Werner Lanter (www.lanter-edv.ch)
*>
class-id JSON.Window1 is partial
inherits type System.Windows.Window.

working-storage section.
method-id NEW.
procedure division.
invoke self::InitializeComponent()
goback.
end method.

method-id PBLaden_Click.

01 StrReader type System.IO.StreamReader.
01 jsonstring string.

01 restaurants type Restaurants.
01 restaurant type Restaurant.

01 SeqNr binary-long.

01 JavaScriptSer type System.Web.Script.Serialization.JavaScriptSerializer.

procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.

*> Test File existsts
if not type System.IO.File::Exists(F_Filename::Text)
set tbGelesen::Text to "File not found"
exit method
end-if

*> Read File into JSON String
set StrReader to new System.IO.StreamReader(F_Filename::Text)
set jsonstring to "{""Restaurants"":" & StrReader::ReadToEnd() & "}" *> Top Node missing in File

*> Deserialize JSON String into Objects
set JavaScriptSer to new System.Web.Script.Serialization.JavaScriptSerializer().
set restaurants to JavaScriptSer::Deserialize[type Restaurants](jsonstring).

*> Display Number of Restaurants in TextBlock
set tbGelesen::Text to "Anzahl Restaurants: " & restaurants::Restaurants::Count::ToString()

*> Set Sequence Number for Restaurants
move 0 to SeqNr
perform varying restaurant thru restaurants::Restaurants
add 1 to SeqNr
set restaurant::SeqNr to SeqNr
end-perform

*> Set Restaurant-List as ItemsSource of DataGrid
set RestaurantGrid::ItemsSource to restaurants::Restaurants.

end method.

method-id PBSchliessen_Click.
procedure division using by value sender as object e as type System.Windows.RoutedEventArgs.

invoke self::Close().

end method.

end class.

class-id Restaurants.

working-storage section.

01 ws-Restausrants type System.Collections.Generic.List [type Restaurant] property as "Restaurants".

end class.

class-id Restaurant.

working-storage section.

01 w-SeqNr binary-long property as "SeqNr".
01 property1 string property as "Enseigne".
01 property2 string property as "Nom_du_restaurant".
01 property3 string property as "FR".
01 property4 string property as "Nom_Exploitant_1".
01 property5 string property as "Ville_Resto".
01 property5b type DateTime property as "Ouverture".
01 property6 string property as "TVA_intracom".
01 property7 string property as "Horaire_Drive_Lundi".
01 property8 string property as "URL_Page_locale".

end class.
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Import json data

Vielen Dank Herr Lanter dass Sie ihre Erfahrungen der Community zur Verfügung stellen, dies müsste noch viel mehr gemacht werden, um anderen Entwickler zu helfen / Thank you Mr Lanter to give your experience to the community! We must to this more and more to help other programmers
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.