Search Unity

How To Separate Json Parameter Function to get values i need ?

Discussion in 'Scripting' started by m-y, May 4, 2020.

  1. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    Hello i just found that i can't send more than one parameter to a Json Function so i did array of string to send to the function parameter

    Code (CSharp):
    1. object[] tempStorage = new object[2];
    2.                              tempStorage[0] = ExpName;
    3.                              tempStorage[1] = ExpName + pdfName;
    4.                        
    5.                              Application.ExternalCall("OpenPDFUIButton", tempStorage);

    in json file how to be able to separate those 2 values to get the value i want


    Code (CSharp):
    1.  function OpenPDFUIButton (expNameAndFileName)
    2. {
    3. var PName = "http://21.32.56/Virtual/Files/"+expName+"/"+expNameAndFileName;
    4. }
     
  2. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    275
    Never saw that method before (and it says its obsolete) but as you function probably is JavaScript, I guess
    Code (CSharp):
    1. function OpenPDFUIButton (names)
    2. {
    3. var PName = "http://21.32.56/Virtual/Files/"+names[0]+"/"+names[1];
    4. }
    should do the trick?
     
  3. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    i will try it it
     
  4. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    are you sure of this Answer ?
     
  5. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    275
    Absolutely not!
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    based on the documentation: https://docs.unity3d.com/ScriptReference/Application.ExternalCall.html

    1. First off this is an obsolete way to call JS functions. There's a better way here: https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
    2. You probably want to make your argument a string[] instead of an object[]. The docs seem to suggest that other types besides what it lists will be sent as the ToString() method of that object. ToString() of object[] is probably not what you want.