I am using a json string like this in a test class.
[{
"id":"01t4B000000XrvhQAC",
"name":"abc123",
"DateRange":{"startDate":"2020-02-17","endDate":"2020-02-26"}
}]
Now instead of hard coding id, I want to use a variable named prdId
.
How can I do this? I tried putting prdId
there, it says,
System.JSONException: Unexpected character ('p' (code 112)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:9]
Best Answer
Omitting the rest of the structure for brevity, you can do something like the following:
I tend to prefer creating a class to represent the structure and then serialize that.
Then in your test: