I am trying to get data from the server, but the server’s response is like this:
<br />
<b>Warning</b>: Undefined variable $response in <b>/home/sasansaf/techblog.sasansafari.com/Techblog/api/article/Model/ArticleModel.php</b> on line <b>191</b><br />
<br />
<b>Warning</b>: foreach() argument must be of type array|object,
null given in <b>/home/sasansaf/techblog.sasansafari.com/Techblog/api/article/Model/ArticleModel.php</b> on line <b>125</b><br />
<br />
<b>Warning</b>: Undefined variable $tags in <b>/home/sasansaf/techblog.sasansafari.com/Techblog/api/article/Model/ArticleModel.php</b> on line <b>175</b><br />
{
"info": {
"id": "19",
"title": "فلاتر",
"content": "من متن و بدنه اصلی مقاله هستم ، اگه میخوای من رو ویرایش کنی و یه مقاله جذاب بنویسی ، نوشته آبی رنگ بالا که نوشته "ویرایش متن اصلی مقاله" رو با انگشتت لمس کن تا وارد ویرایشگر بشی",
"image": "/Techblog/assets/upload/images/article/20221218092957.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "7",
"status": "0",
"created_at": "۱۴۰۱/۹/۲۷"
},
"isFavorite": false,
"related": [
{
"id": "18",
"title": "فلاتر",
"image": "/Techblog/assets/upload/images/article/20221218091728.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "11",
"status": "0",
"created_at": "۱۴۰۱/۹/۲۷"
},
{
"id": "19",
"title": "فلاتر",
"image": "/Techblog/assets/upload/images/article/20221218092957.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "7",
"status": "0",
"created_at": "۱۴۰۱/۹/۲۷"
},
{
"id": "24",
"title": "آموزش زبان انگلیسی",
"image": "/Techblog/assets/upload/images/article/20221219074227.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "6",
"status": "0",
"created_at": "۱۴۰۱/۹/۲۸"
},
{
"id": "46",
"title": "ابنجا عنوان مقاله قرار میگیره! پس یه عنوان جذاب انتخاب کن.",
"image": "/Techblog/assets/upload/images/article/20230107133032.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "",
"view": "2",
"status": "0",
"created_at": "۱۴۰۱/۱۰/۱۷"
},
{
"id": "77",
"title": "بروشورر",
"image": "/Techblog/assets/upload/images/article/20230315182040.instagram",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "0",
"status": "0",
"created_at": "۱۴۰۱/۱۲/۲۴"
},
{
"id": "88",
"title": "uy",
"image": "/Techblog/assets/upload/images/article/20230405035448.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱/۱۶"
},
{
"id": "89",
"title": "uy",
"image": "/Techblog/assets/upload/images/article/20230405035545.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱/۱۶"
},
{
"id": "90",
"title": "uy",
"image": "/Techblog/assets/upload/images/article/20230405035547.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱/۱۶"
},
{
"id": "91",
"title": "uy",
"image": "/Techblog/assets/upload/images/article/20230405055919.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱/۱۶"
},
{
"id": "120",
"title": "اینجا عنوان مقاله قرار میگیره،یه عنوان جذاب انتخاب کن",
"image": "/Techblog/assets/upload/images/article/20230608195254.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "1",
"status": "0",
"created_at": "۱۴۰۲/۳/۱۸"
},
{
"id": "144",
"title": "dsfsdfh",
"image": "/Techblog/assets/upload/images/article/20230910063715.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "1",
"status": "0",
"created_at": "۱۴۰۲/۶/۱۹"
},
{
"id": "150",
"title": "تست عنوان",
"image": "/Techblog/assets/upload/images/article/20230921155019.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "4",
"status": "0",
"created_at": "۱۴۰۲/۶/۳۰"
},
{
"id": "151",
"title": "تست عنوان",
"image": "/Techblog/assets/upload/images/article/20230921155110.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "2",
"status": "0",
"created_at": "۱۴۰۲/۶/۳۰"
},
{
"id": "154",
"title": "عکس متن انگلیسی",
"image": "/Techblog/assets/upload/images/article/20230922075402.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "4",
"status": "0",
"created_at": "۱۴۰۲/۶/۳۱"
},
{
"id": "157",
"title": "who?me?",
"image": "/Techblog/assets/upload/images/article/20230922091722.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "27",
"status": "0",
"created_at": "۱۴۰۲/۶/۳۱"
},
{
"id": "164",
"title": "yfgkb",
"image": "/Techblog/assets/upload/images/article/20231001115409.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "1",
"status": "0",
"created_at": "۱۴۰۲/۷/۹"
},
{
"id": "168",
"title": "hguhf",
"image": "/Techblog/assets/upload/images/article/20231001120959.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۷/۹"
},
{
"id": "198",
"title": "wewe",
"image": "/Techblog/assets/upload/images/article/20231029145614.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۸/۷"
},
{
"id": "199",
"title": "wewe",
"image": "/Techblog/assets/upload/images/article/20231029145646.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۸/۷"
},
{
"id": "200",
"title": "wewe",
"image": "/Techblog/assets/upload/images/article/20231029145653.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۸/۷"
},
{
"id": "253",
"title": "wewe",
"image": "/Techblog/assets/upload/images/article/20231104190629.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "Ahmad",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۸/۱۳"
},
{
"id": "254",
"title": "wewe",
"image": "/Techblog/assets/upload/images/article/20231104190635.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "Ahmad",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۸/۱۳"
},
{
"id": "255",
"title": "مفهوم نوآوری باز",
"image": "/Techblog/assets/upload/images/article/20231114102501.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "54",
"status": "0",
"created_at": "۱۴۰۲/۸/۲۳"
},
{
"id": "257",
"title": "❤️ i mew you",
"image": "/Techblog/assets/upload/images/article/20231116112751.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "9",
"status": "0",
"created_at": "۱۴۰۲/۸/۲۵"
},
{
"id": "259",
"title": "مفهوم اکوسیستم کارآفرینی",
"image": "/Techblog/assets/upload/images/article/20231117191005.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "8",
"status": "0",
"created_at": "۱۴۰۲/۸/۲۶"
},
{
"id": "317",
"title": "کاراکتر",
"image": "/Techblog/assets/upload/images/article/20240219061026.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "14",
"status": "0",
"created_at": "۱۴۰۲/۱۱/۳۰"
},
{
"id": "318",
"title": "کاراکتر",
"image": "/Techblog/assets/upload/images/article/20240219062634.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "13",
"status": "0",
"created_at": "۱۴۰۲/۱۱/۳۰"
},
{
"id": "319",
"title": "کاراکتر",
"image": "/Techblog/assets/upload/images/article/20240219062643.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "4",
"status": "0",
"created_at": "۱۴۰۲/۱۱/۳۰"
},
{
"id": "320",
"title": "کاراکتر",
"image": "/Techblog/assets/upload/images/article/20240219062651.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱۱/۳۰"
},
{
"id": "321",
"title": "کاراکتر",
"image": "/Techblog/assets/upload/images/article/20240219062704.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۲/۱۱/۳۰"
},
{
"id": "355",
"title": "ماشین لرنینگ",
"image": "/Techblog/assets/upload/images/article/20240502134120.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": null,
"view": "2",
"status": "0",
"created_at": "۱۴۰۳/۲/۱۳"
},
{
"id": "381",
"title": "آره بابا",
"image": "/Techblog/assets/upload/images/article/20240520092835.jpg",
"cat_id": "4",
"cat_name": "سخت افزار",
"author": "''",
"view": "0",
"status": "0",
"created_at": "۱۴۰۳/۲/۳۱"
}
],
"tags": null
}
I don’t have access to the backend developer to solve this problem, so how can I solve this problem with Flutter?
This is my piece of code in getting data from the server side
Future<dynamic> getMethod(String url) async {
Dio dio = Dio();
dio.options.headers['content-type'] = 'application/json';
var response= await dio
.get(url,
options: Options(responseType: ResponseType.json, method: 'Get'))
.then((response) {
//log(response.toString());
return response;
});
return response;
}
This is an error:
Exception has occurred.
–
DioException (DioException [unknown]: null Error: FormatException: Unexpected character (at character 1) <br /> ^ )
this is an error
2
Answers
Change
ResponseType.json
toResponseType.plain
You can add an interceptor to modify the returned data format so that you can get the json format inside. The following is a simple example. More adjustments and tests should be done in actual use.