JSON:串连价值2字符串值 [英] JSON: Concatenate 2 string values in value

查看:142
本文介绍了JSON:串连价值2字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个JSON这样的:

Hi I have a JSON like:

{
"name" : "avg",
"code" : {"value":" import android 
                    droid = android.Android() 
                    droid.makeToast('Hello, Android!')",
    "type":"PythonScript"
    } 
}

不过,在值字段(Android的Python脚本)我需要3语句之间一个换行符。喜欢的东西,

However, in value field(Python script for Android) I need a newline character between the 3 statements. Something like,

"value":"import android "  + "\n" + "droid = android.Android()" + "\n" + "droid.makeToast('Hello, Android!')"

是否有可能做到这一点?在此先感谢:)

Is it possible to do this? Thanks in advance :)

推荐答案

其更好地配置您的服务器来发送您 HTML-CN codeD 字符串值。然后,它会更容易重新构造并显示的TextView ,例如为

Its better to configure your server to send you HTML-encoded value string. Afterwards, it would be easier to re-construct and show in TextView, for e.g.

您预期的JSON响应:

Your expected Json response:

{
    "name": "avg",
    "code": {
        "value": "import android<br />droid = android.Android()<br />droid.makeToast('Hello, Android!')",
        "type": "PythonScript"
    }
}

在您阅读的的字符串:

String html_encoded_string = "import android<br />droid = android.Android()
<br />droid.makeToast('Hello, Android!')";

那么它更容易把它的的TextView 的使用HTML编码:

yourTextView.setText(Html.fromHtml(html_encoded_string));

这篇关于JSON:串连价值2字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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