-2

I've JSON Response Values, How can i integrate those Values in UI(User Interface)

Ex:{
    "available":"N",
    "code":"3E",
    "name":"3rd AC ECONOMY"
}

in UI Fields

immu
  • 21
  • 1
  • 3

2 Answers2

1

Let me clear this, If you have response data and want to display in a textbox or any other HTML control then try below code:

var data = {
    "available":"N",
    "code":"3E",
    "name":"3rd AC ECONOMY"
}
console.log(data);
document.getElementById('available').value = data.available;
document.getElementById('code').value = data.code;
document.getElementById('name').value = data.name;
<!DOCTYPE html>
<html lang="en-US">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>
<label for="Available Seats">Available Seats</label>
  <input type="text" name="available" id="available"><br>
  <label for="code">Code</label>
  <input type="text" name="code" id="code" value="female"><br>
  <label for="name">Name</label>
  <input type="text" name="name" id="name"><br><br>

</body>
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
0

Well, this question is rather ambiguous, as you didn’t even mention what Programming Language or Framework you use in your Frontend.

But to give you a start, assuming you use plain JavaScript:

First convert the JSON-String into a JavaScript object

let jsObject = JSON.parse(jsonString);

Then show its fields in the console of the browser

console.log('available: ', jsObject.available);
console.log('code: ', jsObject.code);
console.log('name: ', jsObject.name);
  • I just have an Rest API URL!! With JSON response values , I need to Display those values in Text fields , so that it will be have look and feel !! Say Flight seat availability json response , how can we integrate into a HTML so that it will appear a good look and feel – immu Jul 08 '18 at 14:49
  • 1
    Okay, you have an URL. But this is only half of the story. How do you call/use it? A plain HTML-Page with plain JavaScript that then does the REST-call? Or do you use a Framework like Angular, REACT, KnockOut? –  Jul 08 '18 at 14:53
  • yes , I have an URL with API key , my Q is if I develop a HTML page with three text fields (3 json response values ) now how can I call my URL to those three fields ? – immu Jul 08 '18 at 14:55