You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Duto <ol...@pasteur.fr> on 2011/04/18 19:28:07 UTC

json and array

I have a problem with JSON and Array of String :

public class Test {
    private String[] arrayString = new String[] {"row1", "row2", "row3"};


    public String[] getArrayString() {
        return arrayString;
    }

    public void setArrayString(String[] arrayString) {
        this.arrayString = arrayString;
    }

    public static void main(String[] args) {
        System.out.println(JSON.containsKey(new BeanAdapter(new Test()),
"arrayString[0]"));
    }
}

I get this error : 

Exception in thread "main" java.lang.IllegalArgumentException: Property "0"
not found.
	at org.apache.pivot.json.JSON.containsKey(JSON.java:244)
	at Test.main(Poub.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


If someone can help me.

Best regards 

Duto


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835305.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: json and array

Posted by Duto <ol...@pasteur.fr>.
oki thx G

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835646.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: json and array

Posted by Greg Brown <gk...@verizon.net>.
The JSON class only works with Pivot collections. However, if you want to use a JDK list, you can wrap it in a ListAdapter.

On Apr 18, 2011, at 2:51 PM, Duto wrote:

> no I use jdk list 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835595.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: json and array

Posted by Duto <ol...@pasteur.fr>.
no I use jdk list 

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835595.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: json and array

Posted by Greg Brown <gk...@verizon.net>.
Are you using a Pivot list or a JDK list? With a Pivot list, the example code works fine for me.

On Apr 18, 2011, at 2:30 PM, Duto wrote:

> I am trying but same error : 
> 
> public class Test {
>    private List<String> listString = new ArrayList<String>();
> 
>    public Test() {
>        listString.add(0, "row1");
>        listString.add(1, "row2");
>        listString.add(2, "row3");
>    }
> 
>    public List<String> getListString() {
>        return listString;
>    }
> 
>    public void setListString(List<String> listString) {
>        this.listString = listString;
>    }
> 
>    public static void main(String[] args) {
>        System.out.println(JSON.containsKey(new BeanAdapter(new Test()),
> "listString[0]"));
>    }
> }
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835512.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: json and array

Posted by Duto <ol...@pasteur.fr>.
I am trying but same error : 

public class Test {
    private List<String> listString = new ArrayList<String>();

    public Test() {
        listString.add(0, "row1");
        listString.add(1, "row2");
        listString.add(2, "row3");
    }

    public List<String> getListString() {
        return listString;
    }

    public void setListString(List<String> listString) {
        this.listString = listString;
    }

    public static void main(String[] args) {
        System.out.println(JSON.containsKey(new BeanAdapter(new Test()),
"listString[0]"));
    }
}

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835512.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: json and array

Posted by Greg Brown <gk...@verizon.net>.
JSONSerializer doesn't work with arrays - it only works with Lists (since lists can be dynamically sized, whereas arrays cannot). Try changing String[] to ArrayList<String> and it should work fine.

On Apr 18, 2011, at 1:28 PM, Duto wrote:

> I have a problem with JSON and Array of String :
> 
> public class Test {
>    private String[] arrayString = new String[] {"row1", "row2", "row3"};
> 
> 
>    public String[] getArrayString() {
>        return arrayString;
>    }
> 
>    public void setArrayString(String[] arrayString) {
>        this.arrayString = arrayString;
>    }
> 
>    public static void main(String[] args) {
>        System.out.println(JSON.containsKey(new BeanAdapter(new Test()),
> "arrayString[0]"));
>    }
> }
> 
> I get this error : 
> 
> Exception in thread "main" java.lang.IllegalArgumentException: Property "0"
> not found.
> 	at org.apache.pivot.json.JSON.containsKey(JSON.java:244)
> 	at Test.main(Poub.java:24)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> 
> 
> If someone can help me.
> 
> Best regards 
> 
> Duto
> 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/json-and-array-tp2835305p2835305.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.