在javascript中将JSONArray转换为String以发送到java [英] Converting JSONArray to String in javascript to send to java

查看:145
本文介绍了在javascript中将JSONArray转换为String以发送到java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Android应用程序使用phonegap。 java调用一些显示网页的HTML,HTML使用javascript作为函数。现在在javascript中,我使用HTML中的参数进行JSON调用。问题是我需要发送这个JSONArray回到Java类。但是,当我使用

I am working with an android app that uses phonegap. The java calls some HTML that displays a web page and the HTML uses javascript for functions. Now in the javascript I make a JSON call using parameters from the HTML. The problem is I need to send this JSONArray back to the Java class. However, when I use

JavaActivity.parseJson(jsonArray.toString());

(其中jsonArray是JSONArray,parseJson是java活动中的方法)

(where jsonArray is the JSONArray and parseJson is the method in the java activity)

它发送的字符串看起来像这样:

the string that it sends looks something like this:

[{Object:Object}, {Object:Object}, {Object:Object}, .....]

推荐答案

假设jsonArray保存所有的要发送给Java的数据:

Assuming jsonArray holds all the data you want to send to Java do:

var jString = JSON.stringify(jsonArray);

现在'jString'是数组的json编码字符串表示。

Now 'jString' is the json encoded string representation of your array.

这篇关于在javascript中将JSONArray转换为String以发送到java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆