GraphQl仅返回对象而不是数据/查询
我是GraphQl的新手,并且在将我的GraphQl响应解析为一个数组中遇到了麻烦:
var url = "https://data.objkt.com/v2/graphql";
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}
};
const data = JSON.stringify({
query: `{
currency(distinct_on: fa_contract) {
id
}
}`,
});
xhr.send(data);
我回来的响应是:
{"data":{"currency":[{"id":65223}, {"id":2}, {"id":1}]}}
如何获得仅返回对象(括号内的ID)而不是“数据”和“数据”和“货币”零件以便我可以将其解析为阵列?
我尝试使用正则匹配项来提取括号,但我知道那不是正确/理想的方法!
谢谢
I'm new to GraphQL and am having trouble parsing my GraphQL response into an array:
var url = "https://data.objkt.com/v2/graphql";
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}
};
const data = JSON.stringify({
query: `{
currency(distinct_on: fa_contract) {
id
}
}`,
});
xhr.send(data);
The response I get back is:
{"data":{"currency":[{"id":65223}, {"id":2}, {"id":1}]}}
How can I get the response to only return the object (the ids inside the brackets) and not the "data" and "currency" parts so I can proceed to parse it into an array?
I tried using regex matches to extract the brackets but I know that's not the proper/ideal way!
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论