calling a xojo web service with json data

Hi!

I’ve always made simple ws, with call like this

http://www.nice-web-domain.com/api/getCustomers?spain&

then, I get all the parameters passed and used them.

now, I’ve to made a new ws that will be called with data in json (I’ve to parse that json and make some inserts in my local db)

How can I do this?

Ciao Ciro,

if the api requires a json you should create it with api rules using the JSONItem class and then send it as body of a post with URLConnction

Ciao Antonio,

I’m the receiver, the sender is Salesforce. I must provide a ws to parse the Json received and insert its fields in my db

this is an example of it:

{
  "attributes": {
    "type": "Quote",
    "url": "/services/data/v46.0/sobjects/Quote/0Q03E000000I6X9SAK"
  },
  "Id": "0Q03E000000I6X9SAK",
  "Name": "test",
  "FirstGlobalDiscount__c": 43,
  "SecondGlobalDiscount__c": 21,
  "OperatorCode__c": "102",
  "DocumentNumber__c": 54432,
  "ReferenceDocument__c": 21,
  "Status": "C",
  "ExpirationDate": "2019-10-01",
  "CloseDate__c": "2019-10-31",
  "ReferenceModel__c": "STAND",
  "Payment__c": "a003E000003yWLDQA2",
  "Discount": 14.33333333,
  "HigherPaymentDiscount__c": 32,
  "DiscountsGlobalSurcharges__c": 34,
  "ShippingHandling": 1,
  "Agent__c": "00008",
  "CurrencyCode__c": "CHF",
  "SendDate__c": "2019-10-19",
  "DocumentDate__c": "2019-10-10",
  "ForceDiscount__c": false,
  "Port__c": "3",
  "Pricebook2Id": "01s2p000000ChdCAAS",
  "AccountId": "0013E000013N1XaQAK",
  "QuoteLineItems": {
    "totalSize": 2,
    "done": true,
    "records": [
      {
        "attributes": {
          "type": "QuoteLineItem",
          "url": "/services/data/v46.0/sobjects/QuoteLineItem/0QL3E0000009zozWAA"
        },
        "QuoteId": "0Q03E000000I6X9SAK",
        "Id": "0QL3E0000009zozWAA",
        "Quantity": 2,
        "UnitPrice": 1,
        "Discount": 21,
        "Product2Id": "01t3E000002qyqlQAA",
        "TotalPrice__c": 2.03,
        "PricebookEntryId": "01u3E00000GXBZzQAP",
        "Product2": {
          "attributes": {
            "type": "Product2",
            "url": "/services/data/v46.0/sobjects/Product2/01t3E000002qyqlQAA"
          },
          "Id": "01t3E000002qyqlQAA",
          "Name": "Adattatore PVC 90° TUBO PVC Ø90mm",
          "ArticleCode__c": "CPGO090",
          "ProductCode": "CPGO090"
        }
      },
      {
        "attributes": {
          "type": "QuoteLineItem",
          "url": "/services/data/v46.0/sobjects/QuoteLineItem/0QL3E0000009zp0WAA"
        },
        "QuoteId": "0Q03E000000I6X9SAK",
        "Id": "0QL3E0000009zp0WAA",
        "Quantity": 1,
        "UnitPrice": 1,
        "Discount": 1,
        "Product2Id": "01t3E000002qwjwQAA",
        "TotalPrice__c": 2.03,
        "PricebookEntryId": "01u3E00000GXBLNQA5",
        "Product2": {
          "attributes": {
            "type": "Product2",
            "url": "/services/data/v46.0/sobjects/Product2/01t3E000002qwjwQAA"
          },
          "Id": "01t3E000002qwjwQAA",
          "Name": "Adattatore PVC 90x75x3\"",
          "ArticleCode__c": "CPAD90753",
          "ProductCode": "CPAD90753"
        }
      }
    ]
  },
  "Payment__r": {
    "attributes": {
      "type": "Payment__c",
      "url": "/services/data/v46.0/sobjects/Payment__c/a003E000003yWLDQA2"
    },
    "Id": "a003E000003yWLDQA2",
    "Payment__c": "ADD/C"
  },
  "Pricebook2": {
    "attributes": {
      "type": "Pricebook2",
      "url": "/services/data/v46.0/sobjects/Pricebook2/01s2p000000ChdCAAS"
    },
    "Id": "01s2p000000ChdCAAS",
    "External__c": "STAND"
  },
  "Account": {
    "attributes": {
      "type": "Account",
      "url": "/services/data/v46.0/sobjects/Account/0013E000013N1XaQAK"
    },
    "Id": "0013E000013N1XaQAK",
    "Name": "xxx GROUP",
    "Category__c": "POTOP",
    "CommercialCategory__c": "IEC",
    "AccountingCategory__c": "ENEL",
    "MobilePhone__c": "43232332",
    "AgentCode__c": "00004",
    "FiscalCode__c": "4gfff2323",
    "NationalCode__c": "UY",
    "CurrencyCode__c": "BGN",
    "EntryDate__c": "2018-02-25",
    "Address__c": "Zona A.S.I. Fasano Sud SNC",
    "Serial__c": "000000000004532",
    "AccountCode__c": "423",
    "SectorCode__c": "002",
    "RegionCode__c": "BAS",
    "LanguageCode__c": "POL",
    "Payment__c": "a003E000003yWLDQA2",
    "BillingAddress": {
      "city": "Fasano",
      "country": "Italy",
      "geocodeAccuracy": null,
      "latitude": null,
      "longitude": null,
      "postalCode": "72015",
      "state": "Brindisi",
      "street": "Via xxxx"
    },
    "Phone": "0809696000",
    "Payment__r": {
      "attributes": {
        "type": "Payment__c",
        "url": "/services/data/v46.0/sobjects/Payment__c/a003E000003yWLDQA2"
      },
      "Id": "a003E000003yWLDQA2",
      "Payment__c": "ADD/C"
    }
  }
}

You can solve it by using App.HandleSpecialURL. And send the JSON as POST request to /api/ URL (more details in HandleSpecialURL docs)

in the HandleSpecialURL event handler, you save your JSON to a Dictionary as App property, and generate some random key for it.

Then, redirect to the main URL with GET parameter /?token=[your random data].

Now you can access your JSON data from Session and process it.

The idea is not mine, found it there:

https://forum.xojo.com/38613-handlespecialurl/0

You’ll want to use WebApplication.HandleURL or HandleSpecialURL, which have parameters to provide you with the incoming data. More information about web services is here:

https://documentation.xojo.com/topics/communication/internet/accessing_web_services.html

if you receive the JSON and need to parse it then you have only to set what you received as argument for the constructor.

For example say your received document is in a variable named src.

Dim document as new JSONItem(src)

//read the Agent__c value
//use lookup for values that can exists or not
Dim agent as string=document.lookup("Agent__c", "n/a")

//Read the QuoteLineItems structure
dim quoteLineItems=document.lookup("QuoteLineItems", nil)

//Read the record within QuoteLineItems and then read quoteID for the first record
dim record=QuoteLineItems.lookup("record", nil)

if record<>nil and record.count>0 then
dim QuoteId=record.child(0).lookup("QuoteId", "")
end if

Hi! I was able to receive it but I cannot parse this child (Antonio later I’ll try your method)

"QuoteLineItems": {
    "totalSize": 2,
    "done": true,
    "records": [
      {
        "attributes": {
          "type": "QuoteLineItem",
          "url": "/services/data/v46.0/sobjects/QuoteLineItem/0QL3E0000009zozWAA"
        },
        "QuoteId": "0Q03E000000I6X9SAK",
        "Id": "0QL3E0000009zozWAA",
        "Quantity": 2,
        "UnitPrice": 1,
        "Discount": 21,
        "Product2Id": "01t3E000002qyqlQAA",
        "TotalPrice__c": 2.03,
        "PricebookEntryId": "01u3E00000GXBZzQAP",
        "Product2": {
          "attributes": {
            "type": "Product2",
            "url": "/services/data/v46.0/sobjects/Product2/01t3E000002qyqlQAA"
          },
          "Id": "01t3E000002qyqlQAA",
          "Name": "Adattatore PVC 90° TUBO PVC Ø90mm",
          "ArticleCode__c": "CPGO090",
          "ProductCode": "CPGO090"
        }
      },
      {
        "attributes": {
          "type": "QuoteLineItem",
          "url": "/services/data/v46.0/sobjects/QuoteLineItem/0QL3E0000009zp0WAA"
        },
        "QuoteId": "0Q03E000000I6X9SAK",
        "Id": "0QL3E0000009zp0WAA",
        "Quantity": 1,
        "UnitPrice": 1,
        "Discount": 1,
        "Product2Id": "01t3E000002qwjwQAA",
        "TotalPrice__c": 2.03,
        "PricebookEntryId": "01u3E00000GXBLNQA5",
        "Product2": {
          "attributes": {
            "type": "Product2",
            "url": "/services/data/v46.0/sobjects/Product2/01t3E000002qwjwQAA"
          },
          "Id": "01t3E000002qwjwQAA",
          "Name": "Adattatore PVC 90x75x3\"",
          "ArticleCode__c": "CPAD90753",
          "ProductCode": "CPAD90753"
        }
      }
    ]
  },

I don’t know how many items will be in this child, I need to parse it and for every item insert a record in a table.
Where can I get an example?

Is the same. Here the specific code (src is your document …)

Dim document As New JSONItem(src)
Dim QuoteLineItems As JSONItem=document.Lookup("QuoteLineItems", Nil)
If QuoteLineItems<>Nil Then
  Dim records As JSONItem=QuoteLineItems.Lookup("records", Nil)
  If records<>Nil Then
    Dim totalSize As Integer=QuoteLineItems.Lookup("totalSize", 0)
    If totalSize<>records.Count Then
      System.DebugLog "Not matching size"
    Else
      Dim n As Integer=records.Count-1
      For i As Integer=0 To n
        Dim attributeType, attributeUrl, quoteId, id, product2Id, pricebookEntryId, productType, productUrl, productID, productName, productArticleCode__c, ProductCode As String
        Dim quantity, unitPrice, discount As Integer
        Dim totalPrice__c As Double
        Dim theRecord As JSONItem=records.Child(i)
        
        Dim info As JSONItem=theRecord.Lookup("attributes", nil)
        If info<>Nil Then
          attributeType=info.Lookup("type", "")
          attributeUrl=info.Lookup("url", "")
        End If
        
        quoteId=theRecord.Lookup("QuoteId", "")
        id=theRecord.Lookup("Id", "")
        quantity=theRecord.Lookup("Quantity", 0)
        unitPrice=theRecord.Lookup("UnitPrice", 0)
        discount=theRecord.Lookup("Discount", 0)
        product2Id=theRecord.Lookup("Product2Id", "")
        totalPrice__c=theRecord.Lookup("TotalPrice__c", 0.0)
        pricebookEntryId=theRecord.Lookup("PricebookEntryId", "")
        
        info=theRecord.Lookup("Product2", Nil)
        If info<>Nil Then
          Dim info1 As JSONItem=info.Lookup("attributes", Nil)
          If info1<>Nil Then
            productType=info1.Lookup("type", "")
            productUrl=info1.Lookup("url", "")
          End If
          productID=info.Lookup("Id", "")
          productName=info.Lookup("Name", "")
          productArticleCode__c=info.Lookup("ArticleCode__c", "")
          ProductCode=info.Lookup("ProductCode", "")
        End If
        Break
      Next
    End If
  Else
    System.DebugLog "No records in QuoteLineItems"
  End If
Else
  System.DebugLog "No QuoteLineItems in document"
End If

Instead of break you should “save” your data, you have all the needed fields
Instead of system.debugLog you should rise an exception
You have a field TotalSize that probably is the record size, but since you can get it, you can use to check.

Hi Antonio!

your code works like a charm! but I’m getting problems on some fields, for example:

“OperatorCode__c”: “102”,
“DocumentNumber__c”: 54432,
“ReferenceDocument__c”: 21

DocumentNumber__c is returned as 0 (zero), same as OperatorCode

this is my code:

          Dim document As New JSONItem(data)
    '---- testata
    Dim OFRIFDES,OFRIFDOC,OFSTATUS,OFDATSCA,OFDATCHI,OFCODMOD,OFCODAGE,OFCODVAL,OFDATDOC,OFFLFOSC,OFCODPOR as string
    Dim OFCODUTE,OFNUMDOC as integer
    Dim OFSCOCL2,OFSCOCL1,OFSCOPAG,OFSCONTI,OFSPETRA as double
    Dim ShippingHandling,Agent__c,CurrencyCode__c,SendDate__c,DocumentDate__c,ForceDiscount__c,Port__c as string
    
    OFRIFDES=document.Lookup("name","")
    OFSCOCL2=document.Lookup("Discount__c","")
    OFCODUTE=document.Lookup("OperatorCode_c","")
    OFNUMDOC=document.Lookup("DocumentNumber_c","")
    OFRIFDOC=document.Lookup("ReferenceDocument_c","")
    OFSTATUS=document.Lookup("Status","")
    OFDATSCA=document.Lookup("ExpirationDate","")
    OFDATCHI=document.Lookup("CloseDate_c","")
    OFCODMOD=document.Lookup("ReferenceModel_c","")
    OFSCOCL1=document.Lookup("Discount","") '?
    OFSCOPAG=document.Lookup("HigherPaymentDiscount__c","")
    OFSCONTI=document.Lookup("DiscountsGlobalSurcharges__c","")
    OFSPETRA=document.Lookup("ShippingHandling","")
    OFCODAGE=document.Lookup("Agent_c","")
    OFCODVAL=document.Lookup("CurrencyCode__c","")
    OFRIFDOC=document.Lookup("SendDate__c","")
    OFDATDOC=document.Lookup("DocumentDate__c","")
    OFFLFOSC=document.Lookup("ForceDiscount__c","")
    OFCODPOR=document.Lookup("Port__c","")
    
    msgbox(OFNUMDOC.ToText)
    msgbox(OFCODUTE.ToText)
    
    
    '---- account
    Dim ANDESCRI,ABCODCAT,ANCATCOM,ANCATCON,ANNUMCEL,ANCODAG1,ANCODFIS,ANPARIVA,ANNAZION,ANCODVAL,UTDC,AN_EMAIL,ABCODAGE,ABBUDGET,NOCODICE,ANCODICE,ABCODSET,ANCODREG,ANCODLIN as string
    
    Dim Account As JSONItem=document.Lookup("Account", Nil)
    If Account<>Nil Then
      ANDESCRI=account.Lookup("Name","")
      ABCODCAT=account.Lookup("Category__c","")
      ANCATCOM=account.Lookup("CommercialCategory__c","")
      ANCATCON=account.Lookup("AccountingCategory__c","")
      ANNUMCEL=account.Lookup("MobilePhone__c","")
      ANCODAG1=account.Lookup("AgentCode__c","")
      ANCODFIS=account.Lookup("FiscalCode__c","")
      ANPARIVA=account.Lookup("VatNumber__c","")
      ANNAZION=account.Lookup("NationalCode__c","")
      ANCODVAL=account.Lookup("CurrencyCode__c","")
      UTDC=account.Lookup("EntryDate__c","")
      AN_EMAIL=account.Lookup("EmailAddress__c","")
      ABCODAGE=account.Lookup("CustomerResponsibleCommercial__c","")
      ABBUDGET=account.Lookup("CustomerBudget__c","")
      NOCODICE=account.Lookup("Serial__c","")
      ANCODICE=account.Lookup("AccountCode__c","")
      ABCODSET=account.Lookup("SectorCode__c","")
      ANCODREG=account.Lookup("RegionCode__c","")
      ANCODLIN=account.Lookup("LanguageCode__c","")
    Else
      System.DebugLog "No Account in document"
    End If
    
    '---- righe
    Dim QuoteLineItems As JSONItem=document.Lookup("QuoteLineItems", Nil)
    If QuoteLineItems<>Nil Then
      Dim records As JSONItem=QuoteLineItems.Lookup("records", Nil)
      If records<>Nil Then
        Dim totalSize As Integer=QuoteLineItems.Lookup("totalSize", 0)
        If totalSize<>records.Count Then
          System.DebugLog "Not matching size"
        Else
          Dim n As Integer=records.Count-1
          For i As Integer=0 To n
            Dim attributeType, attributeUrl, ODSERIAL, id, product2Id, pricebookEntryId, productType, productUrl, productID, ODDESART, ODCODART, ProductCode As String
            Dim ODQTAMOV, ODPREZZO, ODSCONT1,ODVALRIG As Double
            Dim theRecord As JSONItem=records.Child(i)
            '
            Dim info As JSONItem=theRecord.Lookup("attributes", nil)
            If info<>Nil Then
              attributeType=info.Lookup("type", "")
              attributeUrl=info.Lookup("url", "")
            End If
            '
            ODSERIAL=theRecord.Lookup("QuoteId", "")
            id=theRecord.Lookup("Id", "")
            ODQTAMOV=theRecord.Lookup("Quantity", 0.0)
            ODPREZZO=theRecord.Lookup("UnitPrice", 0.0)
            ODSCONT1=theRecord.Lookup("Discount", 0.0)
            product2Id=theRecord.Lookup("Product2Id", "")
            ODVALRIG=theRecord.Lookup("TotalPrice__c", 0.0)
            pricebookEntryId=theRecord.Lookup("PricebookEntryId", "")
            '
            info=theRecord.Lookup("Product2", Nil)
            If info<>Nil Then
              Dim info1 As JSONItem=info.Lookup("attributes", Nil)
              If info1<>Nil Then
                productType=info1.Lookup("type", "")
                productUrl=info1.Lookup("url", "")
              End If
              productID=info.Lookup("Id", "")
              ODDESART=info.Lookup("Name", "")
              ODCODART=info.Lookup("ArticleCode__c", "")
              ProductCode=info.Lookup("ProductCode", "")
            End If
            MsgBox(ProductCode)
            
            'insert in db
            
            stringa_sql="insert into ESL11ABGENOFF (OFNUMDOC,OFDATDOC,OFRIFDOC,OFSTATUS,OFDATSCA,OFDATCHI,OFCODMOD,OFRIFDES,OFCODVAL,OFCODLIS,OFCODPAG, "
            stringa_sql=stringa_sql+"OFSCOCL1,OFSCOCL2,OFSCOPAG,OFSCONTI,OFFLFOSC,OFSPETRA,OFCODUTE,OFCODAGE,OFCODPOR,ODSERIAL,ODCODART,ODDESART,ODQTAMOV,"
            stringa_sql=stringa_sql+"ODPREZZO,ODSCONT1,ODVALRIG,ANCODICE,ANDESCRI,ANINDIRI,AN___CAP,ANLOCALI,ANPROVIN,ANNAZION,ANTELEFO,ANNUMCEL,ANCODFIS,"
            stringa_sql=stringa_sql+"ANPARIVA,ANCATCON,ANCODPAG,ANCODAG1,ANCODVAL,ANCODLIN,ANCATCOM,AN_EMAIL,ANCODREG,UTDC,NOCODICE,ABCODCAT,ABCODAGE,"
            stringa_sql=stringa_sql+"ABBUDGET,ABCODSET) values ("
            
            stringa_sql=stringa_sql+"'"+OFNUMDOC.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFDATDOC+"',"
            stringa_sql=stringa_sql+"'"+OFRIFDOC+"',"
            stringa_sql=stringa_sql+"'"+OFSTATUS+"',"
            stringa_sql=stringa_sql+"'"+OFDATSCA+"',"
            stringa_sql=stringa_sql+"'"+OFDATCHI+"',"
            stringa_sql=stringa_sql+"'"+OFCODMOD+"',"
            stringa_sql=stringa_sql+"'"+OFRIFDES+"'," 
            stringa_sql=stringa_sql+"'"+OFCODVAL+"'," 
            stringa_sql=stringa_sql+"'"+"'OFCODLIS'"+"',"
            stringa_sql=stringa_sql+"'"+"'OFCODPAG'"+"',"
            stringa_sql=stringa_sql+"'"+OFSCOCL1.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFSCOCL2.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFSCOPAG.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFSCONTI.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFFLFOSC+"',"
            stringa_sql=stringa_sql+"'"+OFSPETRA.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFCODUTE.ToText+"',"
            stringa_sql=stringa_sql+"'"+OFCODAGE+"'," 
            stringa_sql=stringa_sql+"'"+OFCODPOR+"'," 
            stringa_sql=stringa_sql+"'"+ODSERIAL+"',"
            stringa_sql=stringa_sql+"'"+ODCODART+"',"
            stringa_sql=stringa_sql+"'"+ODDESART+"',"
            stringa_sql=stringa_sql+"'"+ODQTAMOV.ToText+"',"
            stringa_sql=stringa_sql+"'"+ODPREZZO.ToText+"',"
            stringa_sql=stringa_sql+"'"+ODSCONT1.ToText+"',"
            stringa_sql=stringa_sql+"'"+ODVALRIG.ToText+"',"
            stringa_sql=stringa_sql+"'"+ANCODICE+"',"
            stringa_sql=stringa_sql+"'"+ANDESCRI+"',"
            stringa_sql=stringa_sql+"'"+"'ANINDIRI'"+"',"
            stringa_sql=stringa_sql+"'"+"'AN___CAP'"+"',"
            stringa_sql=stringa_sql+"'"+"'ANLOCALI'"+"',"
            stringa_sql=stringa_sql+"'"+"'ANPROVIN'"+"',"
            stringa_sql=stringa_sql+"'"+ANNAZION+"',"
            stringa_sql=stringa_sql+"'"+"'ANTELEFO'"+"',"
            stringa_sql=stringa_sql+"'"+ANNUMCEL+"',"
            stringa_sql=stringa_sql+"'"+ANCODFIS+"',"
            stringa_sql=stringa_sql+"'"+ANPARIVA+"',"
            stringa_sql=stringa_sql+"'"+ANCATCON+"',"
            stringa_sql=stringa_sql+"'"+"'ANCODPAG'"+"',"
            stringa_sql=stringa_sql+"'"+ANCODAG1+"',"
            stringa_sql=stringa_sql+"'"+ANCODVAL+"',"
            stringa_sql=stringa_sql+"'"+ANCODLIN+"',"
            stringa_sql=stringa_sql+"'"+ANCATCOM+"',"
            stringa_sql=stringa_sql+"'"+AN_EMAIL+"',"
            stringa_sql=stringa_sql+"'"+ANCODREG+"',"
            stringa_sql=stringa_sql+"'"+UTDC+"',"
            stringa_sql=stringa_sql+"'"+NOCODICE+"',"
            stringa_sql=stringa_sql+"'"+ABCODCAT+"',"
            stringa_sql=stringa_sql+"'"+ABCODAGE+"',"
            stringa_sql=stringa_sql+"'"+ABBUDGET+"',"
            stringa_sql=stringa_sql+"'"+ABCODSET+"')"
            
            
            
            'ps = db.Prepare(stringa_sql)
            msgbox(stringa_sql)
            'ps.SQLExecute
            
            ''msgbox(quoteid+"-"+id+"-"+quantity.ToText+"-"+unitprice.ToText+"-"+discount.ToText+"-"+product2id+"-"+totalPrice__c.ToText+"-"+pricebookEntryId.ToText+"-"+info+"-"+productID+"-"+productName+"-"+productArticleCode__c+"-"+ProductCode)
          Next
        End If
      Else
        System.DebugLog "No records in QuoteLineItems"
      End If
    Else
      System.DebugLog "No QuoteLineItems in document"
    End If

why?

Your code states:
Dim OFCODUTE,OFNUMDOC as integer

then you call
OFCODUTE=document.Lookup(“OperatorCode_c”,"")
OFNUMDOC=document.Lookup(“DocumentNumber_c”,"")

Have you tried with
OFCODUTE=document.Lookup(“OperatorCode_c”,0)
OFNUMDOC=document.Lookup(“DocumentNumber_c”,0)

the second parameters means what to store if the first is null?

in this case the first parameter is not null. I’ll try your suggestion and give you a feedback

Moreover it gives a hint about the type you need.
You may also try to test with a string variable like
dim test as string=document.Lookup(“OperatorCode_c”,“NOT_EXISTS”)
and check what’s in test.
If still empty maybe it is empty, if it is “NOT_EXISTS” then maybe you are searching for the wrong name or in the wrong place.

[quote=458614:@Antonio Rinaldi]Moreover it gives a hint about the type you need.
You may also try to test with a string variable like
dim test as string=document.Lookup(“OperatorCode_c”,“NOT_EXISTS”)
and check what’s in test.
If still empty maybe it is empty, if it is “NOT_EXISTS” then maybe you are searching for the wrong name or in the wrong place.[/quote]

following your examples:
OFNUMDOC=document.Lookup(“DocumentNumber_c”,0) returns 0
dim test as string=document.Lookup(“OperatorCode_c”,“NOT_EXISTS”) returns NOT_EXISTS

this is the piece of Json where are these informations:

{

    "attributes":{
        "type":"Quote",
        "url":"/services/data/v46.0/sobjects/Quote/0Q03E000000I6X9SAK"
    },
    "Id":"0Q03E000000I6X9SAK",
    "Name":"test",
    "FirstGlobalDiscount__c":43,
    "SecondGlobalDiscount__c":21,
    "OperatorCode__c":"102",
    "DocumentNumber__c":54432,
    "ReferenceDocument__c":21,
    "Status":"C",
    "ExpirationDate":"2019-10-01",
    "CloseDate__c":"2019-10-31",
    "ReferenceModel__c":"STAND",
    "Payment__c":"a003E000003yWLDQA2",
    "Discount":14.33333333,
    "HigherPaymentDiscount__c":32,
    "DiscountsGlobalSurcharges__c":34,
    "ShippingHandling":1,
    "Agent__c":"00008",
    "CurrencyCode__c":"CHF",
    "SendDate__c":"2019-10-19",
    "DocumentDate__c":"2019-10-10",
    "ForceDiscount__c":false,
    "Port__c":"3",
    "Pricebook2Id":"01s2p000000ChdCAAS",
    "AccountId":"0013E000013N1XaQAK",
    "QuoteLineItems":{
        "totalSize":2,
        "done":true,
        "records":[
            {
                "attributes":{
                    "type":"QuoteLineItem",
                    "url":"

this is my code:

dim data as string = Request.Entity.DefineEncoding(encodings.UTF8)
    Dim document As New JSONItem(data)
    '---- testata
    Dim OFRIFDES,OFRIFDOC,OFSTATUS,OFDATSCA,OFDATCHI,OFCODMOD,OFCODAGE,OFCODVAL,OFDATDOC,OFFLFOSC,OFCODPOR as string
    Dim OFCODUTE as integer
    Dim OFSCOCL2,OFSCOCL1,OFSCOPAG,OFSCONTI,OFSPETRA as double
    Dim ShippingHandling,Agent__c,CurrencyCode__c,SendDate__c,DocumentDate__c,ForceDiscount__c,Port__c as string
    
    OFRIFDES=document.Lookup("name","")
    OFSCOCL2=document.Lookup("Discount__c","")
    OFCODUTE=document.Lookup("OperatorCode_c",0)
    dim OFNUMDOC as string=document.Lookup("DocumentNumber_c","NOT_EXISTS")
    OFRIFDOC=document.Lookup("ReferenceDoc

the strange thing is that this:

OFDATDOC=document.Lookup(“DocumentDate__c”,"")

works and is on the same node of the json

maybe I found the problem, it seems the name of the field is not correct…

there are two __ (underscores)

Exactly