[Progress Communities] [Progress OpenEdge ABL] Forum Post: GET JSON STRANGE RESULT

  • Thread starter Giancarlo Alberto Somma
  • Start date
Status
Not open for further replies.
G

Giancarlo Alberto Somma

Guest
Hi to ALL, Follow the code for GET JSON clients data. Its seems all corret but the result is very strange. The entity.json file contains this string: ' Progress.Json.ObjectModel.JsonArray_5057 ' insteand to receive json format file. Maybe could you explain me why? Many thanks BLOCK-LEVEL ON ERROR UNDO, THROW. USING Progress.Json.ObjectModel.JsonObject. USING Progress.Json.ObjectModel.ObjectModelParser. USING Progress.Lang.Object. USING OpenEdge.Core.WidgetHandle. USING OpenEdge.Core.String. USING OpenEdge.Core.*. USING OpenEdge.Net.HTTP.IHttpRequest. USING OpenEdge.Net.HTTP.IHttpResponse. USING OpenEdge.Net.HTTP.ClientBuilder. USING OpenEdge.Net.HTTP.RequestBuilder. USING OpenEdge.Net.HTTP.Credentials. DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO. DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO. DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO. DEFINE VARIABLE oRequestBody AS String NO-UNDO. DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO. DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO. DEFINE VARIABLE lcToken AS LONGCHAR NO-UNDO. DEFINE VARIABLE cToken AS CHARACTER NO-UNDO. DEFINE VARIABLE oEntity AS Object NO-UNDO. DEFINE VARIABLE hXmlDoc AS HANDLE NO-UNDO. DEFINE VARIABLE lcHTML AS LONGCHAR NO-UNDO. SESSION:DEBUG-ALERT = TRUE. oRequestBody = new String('username=sage&password=$££££$$$&grant_type=password'). oRequest = RequestBuilder:post(" http://sage.ch/api/v1/token" , oRequestBody) :ContentType('application/x-www-form-urlencoded') :AcceptJson() :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIP VIEW-AS ALERT-BOX. oJsonEntity = CAST(oResponse:Entity, JsonObject). oJsonEntity:Write(JsonString, TRUE). lcToken = oJsonEntity:GetJsonText("access_token"). cToken = oJsonEntity:GetJsonText("access_token"). MESSAGE STRING(JsonString) STRING(lcToken) VIEW-AS ALERT-BOX. //chToken = "Bearer" + STRING(lcToken). oRequest = RequestBuilder:Get(" sage.ch/.../getclients") // Add credentials to the request //:UsingBasicAuthentication(oCredentials) :AddHeader("Authorization","Bearer " + cToken) :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIP oResponse:ContentLength SKIP oResponse:ContentType skip VIEW-AS ALERT-BOX. oEntity = oResponse:Entity. IF TYPE-OF(oEntity, JsonObject) THEN CAST(oEntity, JsonObject):WriteFile( 'c:\ob1\temp\entity.json ', true). ELSE IF TYPE-OF(oEntity, WidgetHandle) THEN DO: hXmlDoc = CAST(oEntity, WidgetHandle):Value. hXmlDoc:save('file', 'temp\entity.xml'). END. ELSE DO: /*IF TYPE-OF(oEntity, String) THEN lcHTML = CAST(oEntity, String):Value. ELSE lcHTML = oEntity:ToString().*/ case true: when type-of(oEntity, String) then lcHTML = cast(oEntity, String):Value. when type-of(oEntity, Memptr) then lcHTML = cast(oEntity, Memptr):GetString(1). when type-of(oEntity, ByteBucket) then lcHTML = cast(oEntity, ByteBucket):GetString(). otherwise lcHTML = oEntity:ToString(). end case. if OpenEdge.Net.MimeTypeHelper:IsXML(oResponse:ContentType) then copy-lob lcHTML to file 'temp/entity.xml'. else if OpenEdge.Net.MimeTypeHelper:Isjson(oResponse:ContentType) then copy-lob lcHTML to file 'temp/entity.json'. else copy-lob lcHTML to file 'temp/entity.txt'. /* Change extension per the Response's ContentType CASE oResponse:ContentType: WHEN 'application/json' THEN COPY-LOB lcHTML TO FILE 'temp/entity.json'. WHEN 'text/html' THEN COPY-LOB lcHTML TO FILE 'temp/entity.html'. WHEN 'application/atom+xml' THEN COPY-LOB lcHTML TO FILE 'temp/entity.xml'. OTHERWISE COPY-LOB lcHTML TO FILE 'temp/entity.txt'. END CASE. */ END.

Continue reading...
 
Status
Not open for further replies.
Top