我想创建格式如下的json数据:
{
"Credential":{
"ref1":"Test",
"ref2":"test",
"ref3":"test"
},
"ref4":"data"
}
Run Code Online (Sandbox Code Playgroud)
我尝试了很多,但我找不到办法做到这一点.谁能帮帮我吗. 编辑:
我可以输入如下数据:
{
"ref1":"Test",
"ref2":"test",
"ref3":"test"
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我需要访问github graphql API以获取有关某个存储库的一些数据。以下curl命令工作正常
curl -i -H "Authorization: bearer myGithubToken" -X POST -d '{"query": "query { repository(owner: \"wso2-extensions\", name: \"identity-inbound-auth-oauth\") { object(expression:\"83253ce50f189db30c54f13afa5d99021e2d7ece\") { ... on Commit { blame(path: \"components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java\") { ranges { startingLine endingLine age commit { message url history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"}' https://api.github.com/graphql
Run Code Online (Sandbox Code Playgroud)
现在我需要调用与Java操作输出相同的方法。这是我尝试过的代码,
public void callGraphqlApi(){
CloseableHttpClient httpClientForGraphql = null;
CloseableHttpResponse httpResponseFromGraphql= null; …Run Code Online (Sandbox Code Playgroud) 我有一个Android应用程序发布到我的sinatra服务.之前我无法读取sinatra服务的参数.但是,在我将内容类型设置为"x-www-form-urlencoded"之后.我能够看到params,但不是我想要的.我得到的东西是我在sinatra服务中提出的请求.
{"{\"user\":{\"gender\":\"female\"},\"session_id\":\"7a13fd20-9ad9-45c2-b308-
8f390b4747f8\"}"=> nil, "splat"=>["update_profile.json"], "captures"=>["update_profile.json"]}
Run Code Online (Sandbox Code Playgroud)
这就是我从我的应用程序发出请求的方式.
StringEntity se;
se = new StringEntity(getJsonObjectfromNameValueList(params.get_params(), "user");
se.setContentType("application/x-www-form-urlencoded");
postRequest.setEntity(se);
private JSONObject getJsonObjectfromNameValueList(ArrayList<NameValuePair> _params, String RootName) {
JSONObject rootjsonObject = new JSONObject();
JSONObject jsonObject = new JSONObject();
if (_params != null) {
if (!_params.isEmpty()) {
for (NameValuePair p : _params) {
try {
if (p.getName().equals(ApplicationFacade.SESSION_ID))
rootjsonObject.put((String) p.getName(), (String) p.getValue());
else
jsonObject.put((String) p.getName(), (String) p.getValue());
} catch (JSONException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} …Run Code Online (Sandbox Code Playgroud)