简体   繁体   中英

How to show my data in plain text in paragraph which is wrapped in JSON text using Jquery?

I'm new in JSON. I'm using Coinbase API which is wrapped in JSON .

Have a look into this code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%> 
<%@ page import="rajendra.arora.bitcoin.CoinbaseExample" %>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>This is foo.</h1>
<p>This is my Amount balance in Coinbase:</p>
<%
    CoinbaseExample ce=new CoinbaseExample();
    String myBal=ce.getHttp("https://api.coinbase.com/v1/account/balance", null);
%>

<p id="demo">
    <%
        out.print(myBal);
    %>
</p>

</body>
</html>

Which shows my Output as follows:

This is foo.

This is my Amount balance in Coinbase:

{"amount":"0.00000000","currency":"BTC"}

I know this is in JSON wrapped. But can you please help me, how to show these data in normal form in div tag using Jquery?

Can you please help me? How to show this in plain Text.

Surely, Help would be appreciated!!

Your myBal is a String, maybe set it as a JSONObject like:

JSONOBject myBal=ce.getHttp("https://api.coinbase.com/v1/account/balance", null);

Then your output:

out.print(myBal.get("amount");
out.print(myBal.get("currency");

Hope this helps :)

In a div this will look like:

<div>
    <%
        out.print(myBal.get("amount");
        out.print(myBal.get("currency");
    %>
</div>

Or maybe

<script>
var myBal = <% out.print(myBal); %>
document.write(myBal.amount);
// or document.write($.parseJSON(myBal.amount));
</script>

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