JavaScript JSON.stringify() not working correctly - Second parameter disappears json stringify works,json.stringify not working,json.stringify not

I have the following object:

var message = {

    default: 'Default',

    GCM: {

        data: {
            title: titleMessage,
            text: textMessage
        }
    }
};

When I realize:

message.GCM = JSON.stringify(message.GCM);

The variable message.GCM gets the following value:

{"data":{"title":"titleMessageValue"}} 

Instead of:

{"data":{"title":"titleMessageValue", "text":"textMessageValue"}} 

Why does it ignores the second variable from my data object? How can I stringify without lose any variables?

Answer:1

This works ok:

var titleMessage = 'This is my title';
var textMessage = 'This is my message';

var message = {
    default: 'Default',
    GCM: {
        data: {
            title: titleMessage,
            text: textMessage
        }
    }
};

message.GCM = JSON.stringify(message.GCM);

But note that:

  • if var textMessage = undefined; it won't appear in the stringify result.
  • if textMessage does not exist it will throw an error.
Answer:2

Why is this code not working? So far I have only got it to work as an input. I need it to work as a label or span. I need the label to count up 1 number on every click. <html> <head> &...

Why is this code not working? So far I have only got it to work as an input. I need it to work as a label or span. I need the label to count up 1 number on every click. <html> <head> &...

  1. label counting machine
  2. label counting machine price
  3. label counting sensor
  4. label counting machine supplier
  5. label counting rewinding machine
  6. label counting scale
  7. label counting system
  8. label counting machine manufacturers
  9. label counting machine suppliers in mumbai
  10. counting label swift
  11. counting label ios
  12. roll label counting machine
  13. automatic label counting machine
  14. rewind label counting inspection table
  15. single label counting machine
  16. spectral counting label-free proteomics
  17. carb counting label reading
  18. label free spectral counting
  19. label free cell counting
  20. carbohydrate counting label reading

I am attempting to add a class to the select element depending on what option is selected. HTML <select class="wordpress"> <option value="1" class="wordpress">Hello</option> &...

I am attempting to add a class to the select element depending on what option is selected. HTML <select class="wordpress"> <option value="1" class="wordpress">Hello</option> &...

  1. select change click
  2. change select value on click
  3. change select option on click
  4. change select option on button click
  5. change select on click jquery
  6. jquery chrome select change/click not working

I want to add an element like this fiddle but I have a problem to compare my strings when a string has a UTF-8 character because "é" is > at all basics letters. <ol class="ingredientList"> ...

I want to add an element like this fiddle but I have a problem to compare my strings when a string has a UTF-8 character because "é" is > at all basics letters. <ol class="ingredientList"> ...

  1. comparing strings that contain backspace

I have simple for you problem with creating JSON using jQuery. I have an admin panel which is based on JSON data. I have allready put all JSON variables into inputs (they are showing). Now I need to ...

I have simple for you problem with creating JSON using jQuery. I have an admin panel which is based on JSON data. I have allready put all JSON variables into inputs (they are showing). Now I need to ...

  1. creating json with python
  2. creating json with javascript
  3. creating json with php
  4. creating json with java
  5. creating json with c#
  6. create json with jq
  7. create json with gson
  8. create json with jackson
  9. create json with multiple objects
  10. create json with dynamic key
  11. create json with array
  12. create json with jquery
  13. create json with js
  14. create json with powershell
  15. create json with newtonsoft
  16. create json with key value pair
  17. create json with gson java
  18. create json with bash
  19. create json with jackson java
  20. create json with objectmapper