我试图将我的Android本地数据库同步到我的网络服务,但是我在将JSON字符串插入mysql时遇到了一些问题,因为我的所有值都是null。 从Android我发送JSON字符串,这是我在Php。
中得到的def chatpage(request, id):
current_id = id
all_conversations = Conversation.objects.all()
return render(request, 'templates/chat/chatexc.html',
{'all_conversations': all_conversations,
'messages': messages,
'current_id': current_id,})
这是我的php文件:
[{
"prop_id": "1",
"edo_sync": "No",
"titulo": "Departamento en renta ",
"actualizacion": "2016:10:25 19:14:33",
"categoria": "Venta",
"superficie": "30m2",
"_id": "1",
"propiedad": "Casa",
"fecha": "10/25/16"
}, {
"prop_id": "1",
"edo_sync": "No",
"titulo": "Casa en renta",
"actualizacion": "2016:10:27 13:30:08",
"categoria": "Venta",
"superficie": "100m2",
"_id": "2",
"propiedad": "Casa",
"fecha": "10/25/16"
}, etc...
}]
这是我的类来插入数据。
<?php
try
{
include("constantes.php");
//Recibimos Objeto Json
$Propiedad = $_POST["PropiedadPost"];
if (!get_magic_quotes_gpc()) {
echo "activado";
$Propiedad = stripslashes($Propiedad);
//Decode JSON into an Array
$data = json_decode($Propiedad );
print_r ($data);
$options = array('uri' => URL_BASE,'location' => WEBSERVICE);
$client = new SoapClient(NULL, $options);
for($i=0; $i<count($data) ; $i++)
{
//Store prop into MySQL DB
$response = $client->InsertarPropiedad($data[$i]);
print_r ($data[$i]);
echo $response;
}
}
}catch(Exception $e){
echo "Error:".$e->getMessage();
}
?>
我收到的消息:
&#34; SQLSTATE [23000]:完整性约束违规:1048列 &#39; PROP_ID&#39;不能为空&#34;