简体   繁体   中英

How to grab part of JSON string?

            this.on('success', function(file, responseText) { 
                var theID = JSON.stringify(responseText);
                alert(theID);

                window.location.href = ('want to put something here');    

            });

The alert is giving me:

{"message":"success","fileID":399}

and I would like to grab the fileID value, which in this case would be 399. Thank you.

Simply

window.location.href = responseText.fileID;

will do since responseText is already JSON

this.on('success', function(file, responseText) { 
            var theID = JSON.stringify(responseText);
            alert(theID);

            if(responseText.fileID == 399) {
                // Do something
            }
            window.location.href = ('want to put something here');    

        });

If responseText is already in JSON format, then :

   responseText.fileID

if it is in String format, then first parse it:

var json = JSON.parse(responseText);
alert(json.fileID);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM