Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This function decodes a JSON formatted string to a DRUDR.

Code Block
void jsonDecodeUDRjsonDecodeUdr ( string jsonString,
                     DRUDR udr,                                    
                     boolean requireExactMapping (optional) )   

...

Info
titleExample - Encoding UDR to JSON and decoding the result

 Ultra:

Code Block
languagetext
themeEclipse
internal itemUDR {
    int itId;
    string itDescription;      
    string itMisc1 : optional;
    list<string> itMisc2 : optional;   
};

internal transactionUDR {
    int trId ;
    string trDescription;
    float amount;
    long trDate;
    map<string, itemUDR> trItems;
    boolean trProcessed;
    ipaddress trSourceIP;  
    
};


APL:

Code Block
import ultra.JSON_EXAMPLE.ULTRA_JSON_EXAMPLE;

consume {  
    //Item 1
    itemUDR item1 = udrCreate(itemUDR);
    item1.itId = 1;
    item1.itDescription = "Item1";  
    item1.itMisc2 = listCreate(string);
    listAdd(item1.itMisc2, "abc");
    listAdd(item1.itMisc2, "def");
    listAdd(item1.itMisc2, "ghi"); 
     
    //Item2
    itemUDR item2 = udrCreate(itemUDR);
    item2.itId = 1;
    item2.itDescription = "Item2";
    item2.itMisc1 = "abc";       
      
    //Transaction1        
    transactionUDR transaction1  = udrCreate(transactionUDR);
    transaction1.trId = 1;
    transaction1.trDescription = "Transaction1";
    transaction1.amount = 999.99;
    transaction1.trDate = dateCreateNowMilliseconds();
    transaction1.trItems = mapCreate(string, itemUDR);
    mapSet(transaction1.trItems, "item1Key",item1);  
    mapSet(transaction1.trItems, "item2Key",item1);  
    transaction1.trProcessed = true; 
    transaction1.trSourceIP = ipLocalHost();
     
    //Encode with JSON
    string json;
    json = jsonEncodeUdr(transaction1);        
    bytearray ba;
    strToBA(ba, json); 
    debug("Encoded JSON (" + baSize(ba) + "bytes):\n" + json + "\n" ); 
        
    //Decode from JSON
    transactionUDR transactionIn = udrCreate(transactionUDR);        
    jsonDecodeUdr(json, transactionIn);       
    debug("Decoded JSON:\n" + transactionIn);       



Scroll ignore
scroll-viewportfalse
scroll-pdftrue
scroll-officefalse
scroll-chmtrue
scroll-docbooktrue
scroll-eclipsehelptrue
scroll-epubtrue
scroll-htmlfalse


Next: