phpjayx Posted January 15, 2013 Share Posted January 15, 2013 I'm very new to Java, and a lot of coding in general... I found some code to get browser information of the user and have successfully transfered from my PHP controller file to my .JS file and come to this string (returnString2) {"0":"mozilla","1":"5","name":"mozilla","version":"5"} I know that the returnString2[x] gives me the a piece of the array, but extracting it from there is my problem I want to get at the variable "name", but I'm having trouble getting it. I'm sure its very simple, but if someone could explain I would be greatful!!!! Thanks in advance Link to comment https://forums.phpfreaks.com/topic/273173-troubles-getting-at-data-after-splitting-out-the-array/ Share on other sites More sharing options...
phpjayx Posted January 16, 2013 Author Share Posted January 16, 2013 I have now attempted to use .toString() and I run across teh same problem. The furthest I get down to is if I do a SPLIT again on sp2=sp1[2].split(":"); and then I can grab sp2[2], but the string it writes over to my innerHTML variable includes the quotes, which becomes problematic further down the line.... So I get literally with the quotes "mozilla" Still no luck. Help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/273173-troubles-getting-at-data-after-splitting-out-the-array/#findComment-1406037 Share on other sites More sharing options...
Christian F. Posted January 16, 2013 Share Posted January 16, 2013 json_decode () is what you're looking for. Link to comment https://forums.phpfreaks.com/topic/273173-troubles-getting-at-data-after-splitting-out-the-array/#findComment-1406048 Share on other sites More sharing options...
phpjayx Posted January 17, 2013 Author Share Posted January 17, 2013 That wasn't quite it, I was attempting to do it in my .JS.... But thank you, you lead me down a different path of thinking and I finally got it.. Below is what I came up with in my JS and it works. function parseDataJson(returnValue) { var Datax = $.parseJSON(returnValue); alert(Datax[0]); } Link to comment https://forums.phpfreaks.com/topic/273173-troubles-getting-at-data-after-splitting-out-the-array/#findComment-1406305 Share on other sites More sharing options...
Christian F. Posted January 17, 2013 Share Posted January 17, 2013 Ah, sorry. Didn't notice this was the JS section. Though, glad I was able to be of help none the less. Link to comment https://forums.phpfreaks.com/topic/273173-troubles-getting-at-data-after-splitting-out-the-array/#findComment-1406344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.