我正在尝试向Django中实现的后端API提交角度形式。当我提交表单时,它显示以下错误“字符串索引必须为整数”
发布请求方法
postEntries(formData: MeasurementChange): Observable<any> {
return this.http.post(this.baseUrl + this.postDataUrl, formData);
}
发布请求以以下格式发送
{id: 2, percent_complete: 45}
id: 2
percent_complete: 45
API接受以下格式
[{
"id":1,
"percent_complete": 33
}]
如何将对象包装为API接受的格式/数组?
答案 0 :(得分:1)
创建一个数组,并使用push方法添加对象,
myArray : any = [];
然后
this.myArray.push(yourObj);
答案 1 :(得分:0)
只需使用方括号:
<?php
function fun($var1,$var2)
{
$arr1=array(1,2,3,4);
$arr2=array(10,11,12,13);
foreach($arr1 as $var3)
{
if ($var3 == $var2) {
echo $var3;
foreach ($arr2 as $var3 ) {
echo 'inner';
echo $var3;
if ($var3 == $var2) {
}
}
}
}
}
fun(10,1); // here 2nd loop will work as $var2 will satisfy the first condition.
Output : 1inner10inner11inner12inner13
fun(10,11); // here 2nd loop will no work as $var2 will not satisfy the first condition.
Output : '' //no output