Cease altering the order in the JSON parse process

this is a simple text response:

response = " [{"prefixtodomid":"Sat17Dec2016103310GMT","todo_title":"task 3 changed","is_done_todo":false,"todo_subtitle_field":"\u00a0","prefix_pro_due_date":"","multicheckbox":false,"project_file_list":""},{"prefixtodomid":"Sat17Dec2016103313GMT","todo_title":"ce","is_done_todo":false,"todo_subtitle_field":"\u00a0","prefix_pro_due_date":"","multicheckbox":false,"project_file_list":""},{"prefixtodomid":"Sat17Dec2016103318GMT","todo_title":"dewdw","is_done_todo":false,"todo_subtitle_field":"\u00a0","prefix_pro_due_date":"","multicheckbox":false,"project_file_list":""},{"prefixtodomid":"Sat17Dec2016103321GMT","todo_title":"task 4","is_done_todo":false,"todo_subtitle_field":"\u00a0","prefix_pro_due_date":"","multicheckbox":false,"project_file_list":""},{"prefixtodomid":"Sat17Dec2016181953GMT","todo_title":"task 5","is_done_todo":false,"todo_subtitle_field":"\u00a0","prefix_pro_due_date":"","multicheckbox":false,"project_file_list":{"43":"http:\/\/example\/intra\/wp-content\/uploads\/2016\/11\/1project.png","26":"http:\/\/example\/intra\/wp-content\/uploads\/2016\/11\/2016--\u2039-Le-Blog-OSD-\u2014-WordPress_437.png"}},{"prefixtodomid":"Sat17Dec2016181957GMT","todo_title":"cewcwcwecw","todo_subtitle_field":"\u00a0","project_file_list":{"26":"http:\/\/example\/intra\/wp-content\/uploads\/2016\/11\/2016-10-16-15_26_04-Unyson-\u2039-Le-Blog-OSD-\u2014-WordPress_437.png"}}] "

i converted it to JSON as follows:

var obj = jQuery.parseJSON( response );

now I am iterating through the JSON object:

for (var i = 0; i<Object.keys(obj).length; i++) { 
                (function(index){

                    var haveimage = obj[i].project_file_list;

                    if(haveimage){
                        // some other logic here
                    }

                })(i); // using the value of i
            }

the issue is that 'haveimage' always displays images in the order of their IDs, even if we change the order in the response string. When parsed using parseJSON method, the order reverts based on the ID. Is there any solution to this problem?

If not, what alternative can be used instead of parseJSON?

Thank you :)

Answer №1

An object consists of an unorganized collection of name/value pairs.

To maintain the sequence, you can utilize an array:

[
   {
      "15":"http:\/\/example\/intra\/wp-content\/uploads\/2018\/05\/flower.png"
   },
   {
      "37":"http:\/\/example\/intra\/wp-content\/uploads\/2018\/05\/sunset.jpg"
   }
]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Express and Node.js to display a page populated with information

On my webpage, I currently have a list of Teams displayed as clickable links. When a link for a specific Team is clicked, the Key associated with that Team is extracted and sent to the /team/:key route to retrieve the respective data. If the data retrieval ...

accessing PHP array elements within JSON

How can I access an array of arrays returned from PHP in JSON format? This is the PHP array: $cities = array(); while($row = mysql_fetch_array($result)){ $cityRow= array('cityNo'=>$row['city_no'], 'cityName'=>$row[ ...

Guide to displaying a solitary mathjax equation?

I am currently developing a webpage that MathJax is not compatible with. There are hidden display:none elements, latex text embedded within svgs, and various other challenges. Instead of relying on MathJax to automatically scan my site for equations and de ...

Want to easily switch between pictures in the Gallery?

I've created a gallery using jQuery, CSS & HTML and now I want to implement next and previous image buttons. I have added the buttons to the page and written functions for them, but I am struggling with the implementation. Here is my code, if anyone h ...

Set up an array data by extracting values from an array prop within a Vue component

Within my Vue component, I am dealing with an array prop called selectedSuppliers that consists of objects. My goal is to set up a data property named suppliers and initialize it with the values from selectedSuppliers. However, I do not want any modificati ...

Sending HTML parameters to a PHP file

I have been trying to pass the parameters from the current HTML page to a PHP page using a form. In my header in the HTML, I currently have the following function: <script> function getURLParameter(name) { return decodeURIComponent((new Re ...

Error in TypeScript when utilizing generic callbacks for varying event types

I'm currently working on developing a generic event handler that allows me to specify the event key, such as "pointermove", and have typescript automatically infer the event type, in this case PointerEvent. However, I am encountering an error when try ...

Accessing deeply nested objects from props

After pulling an object from my MongoDB database with Redux and passing it as props to a component, I am facing an issue where I can see the object in the console log but cannot access any information within the object. My objective is to extract specific ...

Exploring Python code to access the value of a JavaScript variable

As a newcomer to Python programming, I appreciate your patience. I have an HTML file containing multiple div layers. When clicked on, each div layer stores a value in a global JavaScript variable. This file is accessed within a webkit.WebView object. My ...

The AJAX callback is unable to access the method of the jQuery plugin

I have a scenario where I am fetching data from an AJAX response and attempting to update a jQuery plugin with that value within the success callback: $.ajax({ url: '/some/url', type: 'GET', dataType: 'json', succ ...

Displaying API response array object in React application

Currently, I am attempting to retrieve information from an API, parse the response content, and then display it in a loop. However, I have encountered a warning message: webpackHotDevClient.js:138 ./src/App.js Line 20: Expected an assignment or function ...

Updating JSON subkey titles with PHP

Trying to assist in reformatting a JSON structure for an existing project, focusing on renaming certain subkeys without changing the values. The current JSON format appears as follows: { "table-name": "Kiwi", "created-on": ...

Retrieve data from a JSON formatted string

When attempting to extract values from JSON data, I am consistently receiving an empty result when trying to display the value. $jsonData = '[[{"transTime":"2013-10-23 17:30:42","Forename":"Ian","Surname":"Graham","Address Line 1":"RG412GX"}]]'; ...

Link PHP with Flex Player for seamless integration

Utilizing the Flex Player component on a local server. The FLV video files are located in bin-debug/Video Source. Here is the PHP code snippet: $id = $_GET["id"]; $media = getDirectoryList("bin-debug/Video Source"); if($media[$id] != null){ ...

Steps for inserting new rows into a table from text fields1. Begin

As someone who is brand new to jquery/html, I am eager to create a diary specifically for logging my long distance running times in a neat table format. Here's the HTML code I have been working on: <head> <title>Running Diary</titl ...

Error in React JS: TypeError - JSON.stringify(...).then is not a valid function

Currently, I am in the process of establishing a connection between my react application and the backend for the login page. For this purpose, I have incorporated a promise to handle the response upon successful login. In my file login.js, the following m ...

I just stumbled upon Jupyter and I'm curious - can I utilize Javascript and store it in the cloud?

Yesterday evening, I stumbled upon Jupyter and began using it alongside Python. It seems like an excellent tool for coding, something that I've been in need of, but I'm not sure if I can integrate JavaScript with it. I noticed there are npm packa ...

Read a file using mmap to extract the number of columns in real-time

In my file, the format is as follows: 1-3-5 2 1 2 3-4-1 2 4-1 2-41-2 3-4 My objective is to determine the number of columns present in this file. I am employing mmap in C to read the file. Initially, I attempted to achieve this using ...

Choose an option using jQuery when another select option box is selected

I have a pair of select boxes that I need to link together based on the selected option in the first box. <select name="abc" id="abc"> <option value="1">A</option> <option value="2">B</option> <option value="3"> ...

Not all records are compatible with PHP Echo when placed within a paragraph

Looking for some assistance with a simple form set up; <div class="formholder"> <form action="column1.php" method="post"> <input type="text" placeholder="URL:" name="url" required=""><br> <input type="t ...