如何将动态值传递给JSON字符串 [英] How to pass dynamic value to a JSON String

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

问题描述

我已经以此方式构造了一个JSON字符串,但无法将动态值传递给它

I have constructed a JSON String this way , but cannot able to pass dynamic values to it

String input = "{\r\n" + 
                    "    \"Level\": 0,\r\n" + 
                    "    \"Name\": \"String\",\r\n" + 
                    "    \"msgName\": \"String\",\r\n" + 
                    "    \"ActualMessage\": \"String\",\r\n" + 
                    "    \"TimeStamp\": \"/Date(-62135596800000-0000)/\"\r\n" + 
                    "}" ;

String message = "this is value  want to pass to the ActualMessage attribute " ;

I need to pass dynamic value to the ActaulMessage atribute 

请告诉我如何?

我尝试了多次尝试和错误,但未能成功.

i have tried number of trial and errors but couldn't able to succeed.

推荐答案

使用字符串串联.

String message = "this is value  want to pass to the ActualMessage attribute " ;
String input = "{\r\n" + 
               "\"Level\": 0,\r\n" + 
               "\"Name\": \"String\",\r\n" + 
               "\"msgName\": \"String\",\r\n" + 
               "\"ActualMessage\": \"" + message + "\",\r\n" + 
               "\"TimeStamp\": \"/Date(-62135596800000-0000)/\"\r\n" + 
               "}" ;

这篇关于如何将动态值传递给JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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