Php 在json对象中插入大字符串
在json中插入大字符串时出现问题 我需要确保在将这个大字符串插入json对象时不会出现错误,方法是在插入之前过滤文章中的特殊字符,如(!@$%^&*()\\\\\';:。/)和笑脸 比如说 如果我有这个jsonPhp 在json对象中插入大字符串,php,mysql,json,xcode,filter,Php,Mysql,Json,Xcode,Filter,在json中插入大字符串时出现问题 我需要确保在将这个大字符串插入json对象时不会出现错误,方法是在插入之前过滤文章中的特殊字符,如(!@$%^&*()\\\\\';:。/)和笑脸 比如说 如果我有这个json { "Article": "article text" } 这是xcode - (IBAction)SendArticleButton:(id)sender { NSString *Article = ArticleTextField.text;
{
"Article": "article text"
}
这是xcode
- (IBAction)SendArticleButton:(id)sender {
NSString *Article = ArticleTextField.text;
NSString *ArticleJson = [NSString stringWithFormat:@"Article={ \"Article\": \"%@\" }",Article];
NSData *PostData = [ArticleJson dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/InsertJson.php"]];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:PostData];
[request setHTTPMethod:@"POST"];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
}
php代码
$Article = $_POST['Article'];
header ('Content-Type: text/html; charset=UTF-8');
$con = mysql_connect("xxxxx","xxxxxx","xxxxx");
mysql_select_db("xxxxx", $con);
mysql_query("SET NAMES utf8");
$Article = utf8_encode(trim($Article));
mysql_query("INSERT INTO `xxxxx`.`xxxxx` (`id`, `Article`) VALUES (NULL, '$Article');");
在数据库中插入值时使用
base64\u encode()
。例如:$Article=base64_编码(utf8_编码(trim($Article))
mysql\u查询(“插入到
xxxxx
xxxxx`(id
,Article
)值(空,$Article');”`在调用header()函数之前和之后,以及在不使用utf8_encode()的情况下,是否尝试在文件中写入$Article。请分享你得到的结果