Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Cómo JavaScript usa variables al leer json

Al igual que el título, traté de usar variables al leer json, pero no funcionó (

 fetch('https://lolimstatic.ml/counts/apis.json').then( (response) => { response.json().then((data) => { const apiListFrame = document.querySelector('#als'); const api = document.createElement('a'); api.classList.add('btns'); api.classList.add('button'); api.classList.add('apilist'); var rns = Math.round(Math.random()*10); colors = ["blue","red","white","orange","pink","green","yellow","skyblue","purple","gray"]; api.style.background = colors[rns]; api.style.width = '200px'; var lstd = Math.round(Math.random()*data[0].counts); api.href = 'https://docs.lolimapis.ml/API/'+ data[0].list[lstd] +'/'; lnm = data[0].list[lstd]; var xhr = new XMLHttpRequest; xhr.open("GET", 'https://lolimstatic.ml/counts/apis/zh.json'); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState = 4) { const res = xhr.responseText; // Here is variables Json api.innerText = res.lnm; apiListFrame.appendChild(api); } } }) } )

Creo que decía esto:

 { "lnm": "" }

Pero quiero leer esto (supongamos que la variable lnm es BingImage):

 { "BingImage": "每日Bing图获取" }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una vez que realiza la llamada Ajax, analiza el JSON y ahora puede usarlo.

 fetch('https://lolimstatic.ml/counts/apis.json').then( (response) => { response.json().then((data) => { const apiListFrame = document.querySelector('#als'); const api = document.createElement('a'); api.classList.add('btns'); api.classList.add('button'); api.classList.add('apilist'); var rns = Math.round(Math.random()*10); colors = ["blue","red","white","orange","pink","green","yellow","skyblue","purple","gray"]; api.style.background = colors[rns]; api.style.width = '200px'; var lstd = Math.round(Math.random()*data[0].counts); api.href = 'https://docs.lolimapis.ml/API/'+ data[0].list[lstd] +'/'; lnm = data[0].list[lstd]; var xhr = new XMLHttpRequest; xhr.open("GET", 'https://lolimstatic.ml/counts/apis/zh.json'); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { // Here is us parsing the JSON const res = JSON.parse(xhr.responseText);; // Here is variables Json api.innerText = res.GitHubUserInfo; apiListFrame.appendChild(api); } } }) } )

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!