Unable to display data received as object from backend ,What is the best way to add options to a select from as a JS object with jQuery?How do I remove a property from a JavaScript object?How can I display a JavaScript object?Convert form data to JavaScript object with jQueryHow do I remove a key from a JavaScript object?Get JavaScript object from array of objects by value of propertyFrom an array of objects, extract value of a property as arrayHow to pass variables and data from PHP to JavaScript?How to display the json data in ejs template?error in angular js directive when open a modal
All ASCII characters with a given bit count
What makes accurate emulation of old systems a difficult task?
Why doesn't the standard consider a template constructor as a copy constructor?
Apply a different color ramp to subset of categorized symbols in QGIS?
Combinatorics problem, right solution?
Negative Resistance
Drawing a german abacus as in the books of Adam Ries
Could moose/elk survive in the Amazon forest?
What does "function" actually mean in music?
Restricting the options of a lookup field, based on the value of another lookup field?
Why do games have consumables?
Why did Rep. Omar conclude her criticism of US troops with the phrase "NotTodaySatan"?
What does MLD stand for?
Why do real positive eigenvalues result in an unstable system? What about eigenvalues between 0 and 1? or 1?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Creating a chemical industry from a medieval tech level without petroleum
What is the best way to deal with NPC-NPC combat?
Is there any pythonic way to find average of specific tuple elements in array?
Should the Product Owner dictate what info the UI needs to display?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
Contradiction proof for inequality of P and NP?
Can someone publish a story that happened to you?
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
Multiple fireplaces in an apartment building?
Unable to display data received as object from backend ,
What is the best way to add options to a select from as a JS object with jQuery?How do I remove a property from a JavaScript object?How can I display a JavaScript object?Convert form data to JavaScript object with jQueryHow do I remove a key from a JavaScript object?Get JavaScript object from array of objects by value of propertyFrom an array of objects, extract value of a property as arrayHow to pass variables and data from PHP to JavaScript?How to display the json data in ejs template?error in angular js directive when open a modal
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random"
, I want to display all the fields inside a modal , When I try to use Object.keys()
, this error is thrown - "cannot convert undefined or null to object".
render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">
<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
</div>
</div>
);
Not Sure what to do as I tried Using Object.keys
but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.
javascript reactjs javascript-objects
add a comment |
I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random"
, I want to display all the fields inside a modal , When I try to use Object.keys()
, this error is thrown - "cannot convert undefined or null to object".
render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">
<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
</div>
</div>
);
Not Sure what to do as I tried Using Object.keys
but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.
javascript reactjs javascript-objects
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11
add a comment |
I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random"
, I want to display all the fields inside a modal , When I try to use Object.keys()
, this error is thrown - "cannot convert undefined or null to object".
render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">
<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
</div>
</div>
);
Not Sure what to do as I tried Using Object.keys
but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.
javascript reactjs javascript-objects
I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random"
, I want to display all the fields inside a modal , When I try to use Object.keys()
, this error is thrown - "cannot convert undefined or null to object".
render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">
<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
</div>
</div>
);
Not Sure what to do as I tried Using Object.keys
but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.
javascript reactjs javascript-objects
javascript reactjs javascript-objects
edited Mar 9 at 8:41
nishant
asked Mar 9 at 7:44
nishantnishant
296
296
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11
add a comment |
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11
add a comment |
3 Answers
3
active
oldest
votes
Check header is not undefined before get values;
<div className="col-lg-6">
<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
add a comment |
render the text in a <pre>
tag and use JSON.stringify
<pre>JSON.stringify(request_data.body,null,2)</pre>
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice thosefrom the string that you are getting from
JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
add a comment |
If a valid response is received.
For Example:
"data":
"headers":
"name": "Nishant",
"value": "random"
var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')
The first option will display the value in data object and the second will display the value inside the headers object.
<pre>responseData.data</pre>
<pre>responseData.data.headers</pre>
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
add a comment |
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%2f55075150%2funable-to-display-data-received-as-object-from-backend%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check header is not undefined before get values;
<div className="col-lg-6">
<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
add a comment |
Check header is not undefined before get values;
<div className="col-lg-6">
<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
add a comment |
Check header is not undefined before get values;
<div className="col-lg-6">
<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
Check header is not undefined before get values;
<div className="col-lg-6">
<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>
</div>
answered Mar 9 at 9:20
aseferovaseferov
2,9322714
2,9322714
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
add a comment |
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .
– nishant
Mar 9 at 9:42
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
yes it is working , i used Object.keys instead of Object.values
– nishant
Mar 9 at 9:52
add a comment |
render the text in a <pre>
tag and use JSON.stringify
<pre>JSON.stringify(request_data.body,null,2)</pre>
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice thosefrom the string that you are getting from
JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
add a comment |
render the text in a <pre>
tag and use JSON.stringify
<pre>JSON.stringify(request_data.body,null,2)</pre>
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice thosefrom the string that you are getting from
JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
add a comment |
render the text in a <pre>
tag and use JSON.stringify
<pre>JSON.stringify(request_data.body,null,2)</pre>
render the text in a <pre>
tag and use JSON.stringify
<pre>JSON.stringify(request_data.body,null,2)</pre>
answered Mar 9 at 8:47
Prithwee DasPrithwee Das
684510
684510
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice thosefrom the string that you are getting from
JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
add a comment |
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice thosefrom the string that you are getting from
JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .
– nishant
Mar 9 at 8:59
You can slice those
from the string that you are getting from JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
You can slice those
from the string that you are getting from JSON.stringify
const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>
– Prithwee Das
Mar 9 at 9:10
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
Oh ok will try that and see ..
– nishant
Mar 9 at 9:44
add a comment |
If a valid response is received.
For Example:
"data":
"headers":
"name": "Nishant",
"value": "random"
var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')
The first option will display the value in data object and the second will display the value inside the headers object.
<pre>responseData.data</pre>
<pre>responseData.data.headers</pre>
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
add a comment |
If a valid response is received.
For Example:
"data":
"headers":
"name": "Nishant",
"value": "random"
var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')
The first option will display the value in data object and the second will display the value inside the headers object.
<pre>responseData.data</pre>
<pre>responseData.data.headers</pre>
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
add a comment |
If a valid response is received.
For Example:
"data":
"headers":
"name": "Nishant",
"value": "random"
var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')
The first option will display the value in data object and the second will display the value inside the headers object.
<pre>responseData.data</pre>
<pre>responseData.data.headers</pre>
If a valid response is received.
For Example:
"data":
"headers":
"name": "Nishant",
"value": "random"
var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')
The first option will display the value in data object and the second will display the value inside the headers object.
<pre>responseData.data</pre>
<pre>responseData.data.headers</pre>
edited Mar 9 at 13:17
answered Mar 9 at 9:17
SreeSree
937922
937922
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
add a comment |
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
I tried , i am getting an error message of unexpected termination of JSON input
– nishant
Mar 9 at 9:43
add a comment |
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%2f55075150%2funable-to-display-data-received-as-object-from-backend%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
so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?
– nishant
Mar 9 at 8:42
The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "
– Sree
Mar 9 at 9:11