Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

JNI ArrayList<Hashtable> to Unity C#?

Discussion in 'Android' started by RzRsEdge, Oct 7, 2015.

  1. RzRsEdge

    RzRsEdge

    Joined:
    Oct 27, 2013
    Posts:
    14
    Hi all,

    can anyone help me with using an ArrayList<Hashtable<String, String>> in C#

    I can get bools, and strings from an android native lib without issue but this one is throwing me,


    Code (CSharp):
    1. public ArrayList<Hashtable<String, String>> getProducts()
    2. {
    3.           return pluginClass.CallStatic<ArrayList<Hashtable<String, String>>>("getProductList");
    4. }
    Many Thanks
     
    Last edited: Oct 7, 2015
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    You can return it as an AndroidJavaObject. What sort of functionality do you need to call on it once it is returned in C# ?
     
  3. RzRsEdge

    RzRsEdge

    Joined:
    Oct 27, 2013
    Posts:
    14
    Hi mate,

    I only need to read the contents of it.

    I've now got,

    Code (CSharp):
    1. public List<Dictionary<String, String>> getProducts()
    2. {
    3.     return pluginClass.CallStatic<AndroidJavaObject>("getProductList");
    4. }
    which throws the error,

    Cannot implicitly convert typeUnityEngine.AndroidJavaObject' toSystem.Collections.Generic.List<System.Collections.Generic.Dictionary<string,st‌ring>>

    Thanks
     
    Last edited: Oct 8, 2015
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    You cannot convert one type to another - one is a Java type, returned as a generic java "object".
    C# knows nothing about that object, it only has some "pointer", pointing to a Java object that lives on the JVM and is part of the (Javao) android code.