Highlighted
Super Contributor.
Super Contributor.
1094 views

Json + Visual Cobol

Hello, I need to make a request, send information in Json and get the returns of this request someone has an example. I found it in C # but this is difficult to translate. To tell you the truth I need to access a payment platform that communication is in Json https://vindi.github.io/api-docs/dist/
Translated by Google.
 
Olá, eu preciso fazer uma requisição, enviar informações em Json e pegar os retornos que desta requisição alguem tem um exemplo. Encontrei em c# mas esta difícil de traduzir. Pra falar a verdade preciso acessar uma plataforma de pagamento que a comunicação é em Json vindi.github.io/.../
Traduzido pelo Google.
0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Json + Visual Cobol

It looks like you are talking about calling a RESTful Web Service using COBOL. This can be done either in managed COBOL by using the HttpClient class or in native code by using the IMTK to generate a client from the JSON Schema file. There is a template in Visual Studio that supports this under the native category.

It isn't always necessary to convert C# examples that you find. If you have a C# example that calls the web service then you could certainly call the C# from COBOL. That might be easier.
0 Likes
Highlighted
Super Contributor.
Super Contributor.

RE: Json + Visual Cobol

Eu não sei trabalhar com Web Restful, e não entendi nada daquele programa, meu Visual Studio 2015 não abriu o projeto que esta lá, a idéia seria criar as chamadas para a API enviando e recebendo a troca de informações. Mas preciso fazer isso em COBOL já que é a linguagem que domino, tentei em JS/Ajax mas não obtive sucesso. Eu sei que tem um "plugin" - Newtonsoft.Json mas ainda estou estudando isso. Mesmo assim agradeço sua colaboração!


I do not know how to work with Web Restful, and I did not understand anything about that program, my Visual Studio 2015 did not open the project that is there, the idea would be to create the calls to the API sending and receiving the information exchange. But I need to do this in COBOL since it is the language I master, I tried in JS / Ajax but I did not succeed. I know it has a "plugin" - Newtonsoft.Json but I'm still studying this. Thank you for your cooperation!

I found this code would have translate, I will try to adapt to my needs

using System.IO;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;

namespace ITSolution.Web.JSON
{
public static class JSONHelper
{
public static string GetJSONString(string url)
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();

using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(
stream, Encoding.UTF8);
return reader.ReadToEnd();
}
}

public static T GetObjectFromJSONString<T>(
string json) where T : new()
{
using (MemoryStream stream = new MemoryStream(
Encoding.UTF8.GetBytes(json)))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(stream);
}
}

public static T[] GetArrayFromJSONString<T>(
string json) where T : new()
{
using (MemoryStream stream = new MemoryStream(
Encoding.UTF8.GetBytes(json)))
{
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(T[]));
return (T[])serializer.ReadObject(stream);
}
}
}
}
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.