Properly formating a For loop from JSON query

Joined
Feb 19, 2020
Messages
22
Reaction score
0
I'm using a for loop to get results in JSON but i'm having a problem getting some objects...

The code that i'm using is below:
Code:
for (var key in myObj) {
       if (myObj.hasOwnProperty(key)) {
var trailers = myObj[key].imagesZip;
document.write(''+ trailers +'\n');
       }
    }
This will get all the images in zip format but i want the mp4 videos.

Here is the JSON query:
Code:
[{"sceneId":"325025","sceneName":"Lights","Stars":"Angelina Jolly","description":"text here","length":"1660","sceneActive":"1","degrees":"180","fps":"60","imagesZip":"https:\/\/site.com\/d\/scene_files\/325025\/images-zip\/Angelina_Jolly_Trailers.zip","trailersZip":"https:\/\/site.com\/d\/scene_files\/325025\/trailers-zip\/Angelina_Jolly_Trailers.zip","trailers":{"5K":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_5k_180_180x180_3dh_LR.mp4?disposition=attachment","Mobile":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_mobile_180_180x180_3dh_LR.mp4?disposition=attachment","Mobile-Low":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_mobile-low_180_180x180_3dh_LR.mp4?disposition=attachment","Oculus":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_oculus_180_180x180_3dh_LR.mp4?disposition=attachment","PSVR":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_psvr_180_sbs.mp4?disposition=attachment","Samsung":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_samsung_180_180x180_3dh_LR.mp4?disposition=attachment","Streaming-High":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_streaming_high_180_180x180_3dh_LR.mp4?disposition=attachment","Streaming-Low":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_streaming_low_180_180x180_3dh_LR.mp4?disposition=attachment"},"posterImage":"https:\/\/site.com\/d\/scene_files\/325025\/poster-image\/1_2.jpg","releaseDate":"2020-03-31 10:00:00","url":"18vr.com\/video\/rae_of_light-325025","tags":["180","test","test","test"]},

I want to be able print with document.write the mp4 video links...
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
Here is the JSON query:
Don't know what you mean by 'query'. This is not a query. It looks like the first element of an array. If you are truly sending an array back to your browser we can handle it easily.
First set a JS array equal to the incoming AJAX:
var arr = this.responseText;
Then
Code:
for (var index = 0; index < arr.length; index++) {
    alert(arr[index]["trailersZip"]);
}

You can't use document.write() when you have more then one response.
Make an area to display your results, give it an ID and do this:
Code:
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>Page Title</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />

<body>
    <p id="para"></p>
<script>
var arr = [{
    "sceneId":"25",
    "degrees":"180",
    "imagesZip":"https:\/\/site.com\/d\/scene_files\/325025\/images-zip\/Angelina_Jolly_Trailers.zip",
    "trailersZip":"https:\/\/site.com\/d\/scene_files\/325025\/trailers-zip\/Angelina_Jolly_Trailers.zip",
    "trailers":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_5k_180_180x180_3dh_LR.mp4?disposition=attachment"
},
{
    "sceneId":"32",
    "degrees":"180",
    "imagesZip":"https:\/\/site.com\/d\/scene_files\/325025\/images-zip\/Angelina_Jolly_Trailers.zip",
    "trailersZip":"https:\/\/site.com\/d\/https:\/\/site.com\/d\/small.zip",
    "trailers":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_5k_180_180x180_3dh_LR.mp4?disposition=attachment"
},
{
    "sceneId":"50",
    "degrees":"180",
    "imagesZip":"https:\/\/site.com\/d\/scene_files\/325025\/images-zip\/Angelina_Jolly_Trailers.zip",
    "trailersZip":"https:\/\/site.com\/d\/https:\/\/site.com\/d\/big.zip",
    "trailers":"https:\/\/site.com\/d\/scene_files\/325025\/trailer\/Angelina_Jolly_trailer_1m_5k_180_180x180_3dh_LR.mp4?disposition=attachment"
}];
var text = '';
for (var index = 0; index < arr.length; index++) {
    text += arr[index]["trailersZip"] + "<br>";
    document.getElementById("para").innerHTML = text;
}
</script>
</body>
</html>
 
Joined
Feb 19, 2020
Messages
22
Reaction score
0
Hi,

Doesn't work i have spend a few days trying to figure it out this one but wasn't able to come up with a working example.

1 - I only can make it work partialy with Internet Explorer. Not all the objects work.

2 - Other browsers like chrome, firefox, etc nothing happens

3 - I was just developing this to beautify the JSON text with some cool elements that i want to include but with this heavy work i may just quit.

4 - I'm starting a private conversation including the json url, this is for the adult industry and is not allowed to share. You can use but don't share.

5 - I'm looking for simple guidelines. A working example with all the objects/array/etc would be nice, i just want to add some cool css and some javascript.

Again do not share the links,

Thanks
 
Joined
Feb 19, 2020
Messages
22
Reaction score
0
You said you will take a look in the weekend and is already Tuesday. I know this ain't dificult to the right person so what's wrong?
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
Getting the time. I'm painting my house and I practice guitar. I'll look at it when I have time. OK.
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
The link you gave me does not show the array you posted in post one.
What you gave me is neither an array nor Json. So before I process this as a string make sure what you gave me is what your working with.
 
Joined
Feb 19, 2020
Messages
22
Reaction score
0
Yes, i just use forum friendly names. The url i gave you is the json source i intend to use.
 

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top