首页 \ 问答 \ Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)

Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)

我正在制作Android 4.4项目。 我有NetworkOnMainThreadException 。 以下是我的流程。

Service(sticky) -> Handler(per 5 minutes) -> Runnable -> HttpPost

Runnable不是一个单独的线程吗? 我在Runnable中使用AsyncTask吗?


I am making Android 4.4 project. I've got NetworkOnMainThreadException. Below is my process.

Service(sticky) -> Handler(per 5 minutes) -> Runnable -> HttpPost

Isn't Runnable a separate thread? Shoud I use AsyncTask in Runnable?


原文:https://stackoverflow.com/questions/22580354
更新时间:2024-04-25 21:04

最满意答案

你在每个loopecho结果。 这就是为什么你的js无法正确解析它的原因。 您应该echo一次(在循环结束时)。

$return_array = array();

foreach ($abc as $key => $value) {
    $temp = array();
    $temp['admin_name'] = $value['uName'];
    $temp['admin_email'] = $value['uEmail'];
    $temp['admin_ip'] = $value['ipAddress'];

    $return_array[] = $temp;
}

 echo json_encode($return_array);

You are echoing the result every loop. That is the reason why your js cant parse it correctly. You should echo it once(on the end of the loop.).

$return_array = array();

foreach ($abc as $key => $value) {
    $temp = array();
    $temp['admin_name'] = $value['uName'];
    $temp['admin_email'] = $value['uEmail'];
    $temp['admin_ip'] = $value['ipAddress'];

    $return_array[] = $temp;
}

 echo json_encode($return_array);

相关问答

更多
  • 您的服务器是否将数据作为Content-Type "*/json" ? 如果没有,请相应地修改响应头。 例如,发送"application/json"会很好。 Is your server sending data as Content-Type "*/json"? If not, modify the response headers accordingly. Sending "application/json" would be fine, for example.
  • 你在每个loop中echo结果。 这就是为什么你的js无法正确解析它的原因。 您应该echo一次(在循环结束时)。 $return_array = array(); foreach ($abc as $key => $value) { $temp = array(); $temp['admin_name'] = $value['uName']; $temp['admin_email'] = $value['uEmail']; $temp['admin_ip'] = $val ...
  • 在使用CURL查看来自两个URL的响应之后,不起作用的那个不是jsonp响应。 这是一个json的回应。 它没有包含在json p工作所需的方法调用中。 不起作用的是 {"io":{"rec_count":12,...}} VS HNCallback({"nextId":null,...}) 看到不同? 由于原始策略相同,您将无法从任一URL获得纯json响应。 因此,您需要使用CORS(如果您控制其他域)或jsonp,就像您当前配置使用的那样,或服务器端代理。 after looking at respo ...
  • 如果您使用.NET作为服务器,例如ASP.NET MVC Web应用程序。 您需要在web.config或JsonConfiguration上更新服务器允许将JSON信息发送到客户端的最大值。 您可以查看本主题中的解决方案: 设置无限的JSON长度 if you're using .NET as server, for example a ASP.NET MVC Web app. You will need to update on the web.config or in your JsonConfigu ...
  • 也许你的标题有问题..尝试以下代码 response.setContentType("application/json"); i'had added this line already.My mistake was that i was not appending callback function name to my json response at the server end. By the way thanks. I got the answer. http://www.ibm.com/deve ...
  • 您的数据是有效的JSON并且是一个数组,因此请使用index来获取数据。 所以你不需要JSON.parse $.post('ajax/name.php', { name: name }, function (data) { for (var i = 0; i < data.length; ++i) var tr = $(''); tr.append("" + data[i].ARTIST + ""); tr.append(" ...
  • 您需要返回json字符串而不是ModelAndView对象。 在ModelAndView对象上调用addOjbect方法时,您正在为模型添加或覆盖一个属性。 ModelAndView api 返回ModelAndView你基本上返回一个带有你想要显示的视图名的字符串,所以你返回的是一个html页面,而不是一个json对象。 你需要做的是返回一个json字符串。 所以它应该是这样的: @ResponseBody public String contentlistObjective(HttpServletReq ...
  • dataType是指请求标头,而不是响应。 如果你没有发回有效的JSON,jQuery将不喜欢它。 你想发送JSON,但你可能想要找回别的东西。 只需删除dataType ,它应该可以正常工作,除非服务器脚本出错。 dataType refers to the request header, not the response. If you are not sending back valid JSON, jQuery won't like it. You want to send JSON, but yo ...
  • 尝试这个: $.each(data, function(i,item){ alert(item.id + " " +item.subcategory); }); each()的第一个参数必须是迭代的对象。 它必须是数据(数据没有属性“对象”)。 提供的函数的第二个参数将是迭代对象的当前项。 Try this: $.each(data, function(i,item){ alert(item.id + " " +item.subcategory); }); The first argum ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)