suzaku15 / android-xmlrpc

Automatically exported from code.google.com/p/android-xmlrpc
0 stars 0 forks source link

Problem parsing array of structs #20

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Connect to the web service for retrieving an array of structs. The service
returns the data specified in the attached XML file.

What is the expected output? What do you see instead?
I expect this data to be convertible to a HashMap but the call function
returnsLjava.lang.Object which I'm unable to parse.

What version of the product are you using? On what operating system?
I'm using the latest version from the SVN. Running Eclipse on Win XP,
developing for Android.

Please provide any additional information below.
The function works smooth with simple structs.

Many-many thanks for providing this great library!!!

Original issue reported on code.google.com by macko19...@googlemail.com on 10 Mar 2010 at 6:19

Attachments:

GoogleCodeExporter commented 8 years ago
Hi folks,
that is my first day using this library and I had the same problem to solve. 
client.call() has the returntype Object. But in our case we expect an array of
HashMaps. Unfortunately we cannot cast Object to HashMap[]. (My programm crashed
trying (HashMap[])client.call(...) ) 
Instead of a directcast to HashMap[] we can do this:

Object[] obj=(Object[]) client.call(...);
for (int i;i<obj.length;i++) {
   HashMap<String, String> map= (HashMap<String, String>) obj[i];
}

In my case I have only members of type String in the struct.

Thanks for this library and I hope I can help with this explanation.

Original comment by chm0...@gmail.com on 20 Mar 2010 at 10:56

GoogleCodeExporter commented 8 years ago
Many thanks for taking the time to post this! I'm sure it will help several 
people!

Original comment by macko19...@googlemail.com on 21 Mar 2010 at 6:08

GoogleCodeExporter commented 8 years ago
Thanks cjm0815, I'll see if I can roll some kind of wrapper into the next 
release.

Original comment by JonTheNiceGuy on 30 Mar 2010 at 8:24

GoogleCodeExporter commented 8 years ago
I'm looking at this, and struggling somewhat to figure out how to add it into 
the release. That said, I'm not great at Java, so I don't really know what 
other types one might expect to receive over an XMLRPC link that one can 
convert into the types within java... so, I don't know what to suggest. Does 
anyone have any suggestions?

Original comment by jon@sprig.gs on 23 Nov 2010 at 9:41

GoogleCodeExporter commented 8 years ago
Its not clear to me why an array would cast directly to a HashMap. Structs 
certainly would because these are unordered key,value pairings. Arrays are 
ordered and don't have key-value pairs...wouldn't a more natural cast be a Java 
vector?? So an array of structs would be Vector<HashMap<String,Object>> or some 
such. There is only so much you can do though because the nesting isn't really 
limited. So you could have an array of structs which have mixed types as 
elements, so it will still be up to the user to cast the appropriate type.

If you can handle some of these casts in the library internally it would really 
improve the usability. 

Original comment by jonefo...@gmail.com on 10 Dec 2010 at 8:22

GoogleCodeExporter commented 8 years ago
Thank you very much you saved my day! :)

Some other tricks?

Original comment by stermi on 23 Jun 2011 at 12:33

GoogleCodeExporter commented 8 years ago
The hashmap solution is working w/ me and it's enough so far.

Original comment by mail.ga...@gmail.com on 15 Apr 2012 at 7:16

GoogleCodeExporter commented 8 years ago
can array two dimension work on this? 
exmp array like this:

Array
(
    [0] => Array
        (
            [first_name] => John
            [last_name] => Doe
            [member_id] => 123435
        )

    [1] => Array
        (
            [first_name] => Robert
            [last_name] => Brown
            [member_id] => 123436
        )

)

Original comment by hermawan...@gmail.com on 4 Apr 2013 at 7:41