I have a JSON object that is passed to me as a String, but the object in its string form contains duplicate properties. I need to temporarily add extra numbers to properties in order to avoid a problem with duplicate JSON properties. As soon as I finish editing the object, I will JSON.Stringify return the object to String and delete the numbers.
Here is the line I passed:
{ "View":{ "Image":{ "BackgroundImage":"Image.png", "Position":[0,0], "Width":320, "Height":480 }, "Button":{ "BackgroundImage":"ButtonTop.png", "Position":[61,83], "Width":217, "Height":58 }, "Button":{ "BackgroundImage":"ButtonBottom.png", "Position":[61,214], "Width":205, "Height":73 }, "TextField":{ "BackgroundImage":"TextFieldLogin.png", "Position":[102,336], "Width":189, "Height":31 }, "Label":{ "Position":[137,100], "Width":72, "Height":20, "Text":"Hi Steve", "FontSize":18, "Color":[0,0,0,1] }, "Label":{ "Position":[43,342], "Width":54, "Height":20, "Text":"Login:", "FontSize":18, "Color":[0,0,0,1] }, "Label":{ "Position":[115,234], "Width":54, "Height":20, "Text":"Button", "FontSize":18, "Color":[0,0,0,1] } } }
Here is how I would like the result to be:
{ "View_1":{ "Image_1":{ "BackgroundImage":"Image.png", "Position":[0,0], "Width":320, "Height":480 }, "Button_1":{ "BackgroundImage":"ButtonTop.png", "Position":[61,83], "Width":217, "Height":58 }, "Button_2":{ "BackgroundImage":"ButtonBottom.png", "Position":[61,214], "Width":205, "Height":73 }, "TextField_1":{ "BackgroundImage":"TextFieldLogin.png", "Position":[102,336], "Width":189, "Height":31 }, "Label_1":{ "Position":[137,100], "Width":72, "Height":20, "Text":"Hi Steve", "FontSize":18, "Color":[0,0,0,1] }, "Label_2":{ "Position":[43,342], "Width":54, "Height":20, "Text":"Login:", "FontSize":18, "Color":[0,0,0,1] }, "Label_3":{ "Position":[115,234], "Width":54, "Height":20, "Text":"Button", "FontSize":18, "Color":[0,0,0,1] } } }
How can I use javascript.replace () to add numbering on demand and then remove numbering on demand?