Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass dynamic value to a JSON String

Tags:

java

json

I have constructed a JSON String this way, but cannot 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 

Please tell me how.

I have tried number of trial and errors but couldn't succeed.

like image 556
Pawan Avatar asked Dec 13 '25 23:12

Pawan


1 Answers

Use string concatenation.

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" + 
               "}" ;
like image 69
chockleyc Avatar answered Dec 16 '25 11:12

chockleyc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!