getting extra [] at the end of json array
I am getting an extra at the end of the json and it is causing me problems. I tried to search why or where these are added but couldn't find anything.
so what I need is [{content},{content},{content}] but I am getting [{content},{content},{content}]
The result should be:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
but instead is:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
The code used:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;
php json
add a comment |
I am getting an extra at the end of the json and it is causing me problems. I tried to search why or where these are added but couldn't find anything.
so what I need is [{content},{content},{content}] but I am getting [{content},{content},{content}]
The result should be:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
but instead is:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
The code used:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;
php json
1
Code here seems ok. Something else afterbreak
can output.
– u_mulder
Nov 22 '18 at 9:39
1
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
1
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output
– Shobi
Nov 22 '18 at 9:39
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42
add a comment |
I am getting an extra at the end of the json and it is causing me problems. I tried to search why or where these are added but couldn't find anything.
so what I need is [{content},{content},{content}] but I am getting [{content},{content},{content}]
The result should be:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
but instead is:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
The code used:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;
php json
I am getting an extra at the end of the json and it is causing me problems. I tried to search why or where these are added but couldn't find anything.
so what I need is [{content},{content},{content}] but I am getting [{content},{content},{content}]
The result should be:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
but instead is:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
The code used:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;
php json
php json
asked Nov 22 '18 at 9:36
Sara KatSara Kat
1067
1067
1
Code here seems ok. Something else afterbreak
can output.
– u_mulder
Nov 22 '18 at 9:39
1
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
1
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output
– Shobi
Nov 22 '18 at 9:39
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42
add a comment |
1
Code here seems ok. Something else afterbreak
can output.
– u_mulder
Nov 22 '18 at 9:39
1
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
1
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output
– Shobi
Nov 22 '18 at 9:39
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42
1
1
Code here seems ok. Something else after
break
can output
.– u_mulder
Nov 22 '18 at 9:39
Code here seems ok. Something else after
break
can output
.– u_mulder
Nov 22 '18 at 9:39
1
1
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
1
1
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output– Shobi
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output– Shobi
Nov 22 '18 at 9:39
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427831%2fgetting-extra-at-the-end-of-json-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427831%2fgetting-extra-at-the-end-of-json-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Code here seems ok. Something else after
break
can output.
– u_mulder
Nov 22 '18 at 9:39
1
put more code, or add exit after json_encode; Probably you have multiple json_encode() which shouldn't be like that
– Robert
Nov 22 '18 at 9:39
1
Try to replace the break at the end with an exit to be sure no follwing code will change your output.
– yunzen
Nov 22 '18 at 9:39
exit(0)
after the echo statement and see output– Shobi
Nov 22 '18 at 9:39
yes you guys are right thanks there was something after break doing it
– Sara Kat
Nov 22 '18 at 9:42