我想将数组数据传递给URL。
我的代码是:

    String[] pointArray=(String[]) hashtable.get("point");


// where all values are coming from hashtable of my webservice.I want to pass this array as a chart data for line graph.

BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);
add(browserField);

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y" +
"&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0" +
"&chs=480x280&chof=validate&chd=t:100,200,300,400,500,600,700&chd=t:"+point";

 browserField.requestContent(url);


但这给了我这个错误:

The parameter 'chd=t:[Ljava.Lang.String@d297c570f' does not match the expected format.


我想将数组传递到此URL以获取图表数据。如何解决这个问题呢?

最佳答案

在网址中

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y"
+"&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0"
+"&chs=480x280&chof=validate&chd=t:100,200,300,400,500,600,700&chd=t:"
+point;


您的点将通过point.toString()转换并添加到此部分的url中

"&chd=t:"+point;


这是chd第二次出现在网址中。因此,实际上仅考虑最后一个chd值。并且不考虑chd = t:100,200,300,400,500,600,700的第一个。

如果要传递chd,则必须位于format chd = t:val,val,val中,其中val表示数据中的值。见an example with a data chd=t:-5,30,-30,50,80,200

chd应该只在URL中出现一次。

因此,您的网址代码应为:

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y"
+ "&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0"
+ "&chs=480x280&chof=validate&chd=t:"+<comma separated list of values>;

10-08 10:58