我将以下#include <iostream>
#include <cctype>
#define MAX_DIGITS 100
typedef int long_hex_t[MAX_DIGITS];
void add( long_hex_t c, long_hex_t a, long_hex_t b )
{
int carry = 0;
for ( int i = 0; i < MAX_DIGITS; ++i )
{
int t = a[i] + b[i] + carry;
c[i] = t % 16;
carry = t / 16;
}
}
void print( long_hex_t h )
{
//
int i;
// skip leading zeros
for ( i = MAX_DIGITS - 1; i >= 0 && h[i] == 0; --i )
;
// all zero
if ( i < 0 )
{
std::cout << '0';
return;
}
// print remaining digits
for ( i; i >= 0; --i )
std::cout << char( h[i] < 10 ? h[i] + '0' : h[i] - 10 + 'A' );
}
void read( long_hex_t h )
{
// skip ws
std::ws( std::cin );
// skip zeros
{
char c;
while ( std::cin.get( c ) && c == '0' )
;
std::cin.putback( c );
}
//
int count;
{
int i;
for ( i = 0; i < MAX_DIGITS; ++i )
{
char c;
if ( !std::cin.get( c ) )
break;
if ( !std::isxdigit( c ) )
{
std::cin.putback( c );
break;
}
c = std::toupper( c );
h[i] = c <= '9'
? ( c - '0' )
: ( c - 'A' + 10 );
}
count = i;
}
// reverse
for ( int i = 0, ri = count - 1; i < count / 2; ++i, --ri )
{
int t = h[i];
h[i] = h[ri];
h[ri] = t;
}
// fill the rest with zero
for ( int i = count; i < MAX_DIGITS; ++i )
h[i] = 0;
}
int main()
{
long_hex_t a;
read( a );
long_hex_t b;
read( b );
long_hex_t c;
add( c, a, b );
print( c );
return 0;
}
传递给我的AJAX电话
JSON object
这是我的AJAX电话:
var contact = {
"accessToken": "xxx-xxx-xxx-xxx-xxx",
"email": "test@test.com",
"customFields": {
"custom7": {"value": "test rep"},
"custom8": {"value": "test title"},
"custom9": {"value": "test@localdev.com"}
}
}
$.ajax({
type: 'POST',
url: 'https://api.mydomain.com/v1/contacts/save',
data: contact,
dataType: 'json',
success: function(data) {
alert(data.errors);
}
});
显示以下内容:
输入JSON无效。如果内容,请求正文必须是有效的JSON type是application / json
我使用jsonlint.com检查了上面的JSON对象并验证了它。 我不明白我做错了什么!
答案 0 :(得分:2)
在传递之前将该json字符串化 -
$.ajax({
type: 'POST',
url: 'https://api.mydomain.com/v1/contacts/save',
data: JSON.stringify(contact),
dataType: 'json',
success: function(data) {
alert(data.errors);
}
});