小编Mat*_*ell的帖子

如何从Retrofit2获取字符串响应?

我正在做android,寻找一种方法来做一个超级基本的http GET/POST请求.我一直收到错误:

java.lang.IllegalArgumentException: Unable to create converter for class java.lang.String
Run Code Online (Sandbox Code Playgroud)

网络服务:

public interface WebService {
    @GET("/projects")
    Call<String> jquery();
}
Run Code Online (Sandbox Code Playgroud)

然后在我的java中:

    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("https://jquery.org")
       // .addConverterFactory(GsonConverterFactory.create())
        .build();

    WebService service = retrofit.create(WebService.class);
    Call<String> signin = service.jquery();

    Toast.makeText(this, signin.toString(), Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)

我实际上只是尝试使用GET请求查询jquery.org/projects并返回它响应的String.怎么了?

如果我尝试实现一个自定义转换器(我在网上找到了一些例子),它抱怨我没有实现抽象方法convert(F),这些都没有.

谢谢.

java android http retrofit2

30
推荐指数
5
解决办法
4万
查看次数

我如何按位XOR两个C char数组?

我觉得愚蠢无法解决这个问题,但我迷失了.我试图XOR两个C字符串.

#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
int main()
{
    char plainone[16]; 
    char plaintwo[16];
    char xor[17];
    strcpy(plainone, "PlainOne");
    strcpy(plaintwo, "PlainTwo");
    int i=0;
    for(i=0; i<strlen(plainone);i++)
        xor[i] ^= (char)(plainone[i] ^ plaintwo[i]);
    printf("PlainText One: %s\nPlainText Two: %s\n\none^two: %s\n", plainone, plaintwo, xor);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的输出是:

$ ./a.out 
PlainText One: PlainOne
PlainText Two: PlainTwo

one^two: 
Run Code Online (Sandbox Code Playgroud)

为什么xor数组不能读作什么?

c arrays bit-manipulation char xor

10
推荐指数
1
解决办法
3万
查看次数

如何在网站上的域名前添加一个词?

我不知道这是否相关,但我正在使用 Django 构建网站。

怎么在域名前加一个词?例如,对于 location: location.website.com,类似于Craigslist为每个城市提供不同 URL 的方式。你怎么做到这一点?

python django dns url

3
推荐指数
1
解决办法
5408
查看次数

无法创建Python单链接列表

首先,我来自C/C++/Java的背景.我决定学习Python以扩展我的技能,并希望深入研究一些Web开发.我只学习了大约两天,我一直在尝试创建一些简单的数据结构.

我收到了很多错误,我无法弄清楚该做什么!我试图研究它,我仍然无法弄明白.我收到传递给我的LinkedList成员函数的位置参数数量的错误,当我拿出它们时,它说我的Node函数定义中没有定义self.

class Node:

    def __init__():
        self.data = None
        self.nextNode = None  

    def set_and_return_Next():
        self.nextNode = Node()
        return self.nextNode

    def getNext():
        return self.nextNode

    def getData():
        return self.data

    def setData(d):
        self.data = d


class LinkedList:

    def buildList(array):
        head = Node()
        head.setData(array[0])
        temp = head
        for i in array:
            temp = temp.set_and_return_Next()
            temp.setData(array[i])
            tail = temp
        return self.head

    def printList():
        tempNode = head
        while(tempNode!=tail):
            print(tempNode.getData())
            tempNode = tempNode.getNext()

myArray = [3, 5, 4, 6, 2, 6, 7, 8, 9, 10, 21]

myList …
Run Code Online (Sandbox Code Playgroud)

python data-structures singly-linked-list

0
推荐指数
1
解决办法
1608
查看次数

为什么这些字符串不能在C++中连接?

我有一个用C++编写的两个测试程序的例子.第一个工作正常,第一个错误.请帮我解释一下这里发生了什么.

#include <iostream>
#include <string>
#include <stdint.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

string randomStrGen(int length) {
static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
string result;
result.resize(length);
for (int32_t i = 0; i < length; i++)
    result[i] = charset[rand() % charset.length()];
return result;
}

int main()
{
ofstream pConf;
pConf.open("test.txt");
pConf << "rpcuser=user\nrpcpassword=" 
     + randomStrGen(15)
     + "\nrpcport=14632"
     + "\nrpcallowip=127.0.0.1"
     + "\nport=14631"
     + "\ndaemon=1"
     + "\nserver=1"
     + "\naddnode=107.170.59.196";
pConf.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)

它打开'test.txt'并写入数据,没问题.但是,这不是:

#include <iostream>
#include <string>
#include <stdint.h>
#include <stdlib.h>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ string string-concatenation char

0
推荐指数
1
解决办法
141
查看次数

为什么python3不加载这个json字符串?

我有一串

b'{"nonce":"820346305172674795","hash":"CF9558F1AC5AA3F4F3D598BAD50D8E0FD15E536A98095C01AD1BA962BDF342D0E37CF6ED595758B3217CA1986238B10EB729D5C5EBCE1523B41328365E936DBE","encryptedMessage":"ABF47CA76B72388B3CA8F4BF95D199D02835C5AED546CC6A6A35663C312093DB05E3765A00211242770136D7F2391A2A69CCA28B4D9695","signature":"09036C211B6386AD0B1D7EDA14AE4C4C77721916C9AF48E7141049E2773098665776AA4B7CC6E12B4B5BD1FBB3B590F41C6254313BAEBA9293D87769F1A4200468747470733A2F2F3139322E3136382E312E38343A353030302F746F67676C655F646F6F722431"}'
Run Code Online (Sandbox Code Playgroud)

那就是print(str(json_string))输出

当我尝试时json.loads(json_string),它说它不能是字节数组,必须是字符串

当我尝试json时。

python encoding json utf-8 python-3.x

0
推荐指数
1
解决办法
3078
查看次数