The JSON object
"Stores create/update": [
{
"id": 780,
"callback": "Stores create/update",
"date": "2021-10-07"
}]
I want string "id :780"
- without using jsonobject.get("id");
CodePudding user response:
You can just concatenate the key with value, so getting value is enough, also parse the json into object first.
// do something to get value (not sure if this is syntax for java)
value = jsonObject[0].id
// then just concat value
ansString = "id :" value
CodePudding user response:
<script>
var js1 = {"Stores create/update": [
{
"id": 780,
"callback": "Stores create/update",
"date": "2021-10-07"
}]};
console.log(JSON.stringify(js1).replace(/.*:\s?(\d{1,}).*/, '"id :$1"'));
</script>