用php从Android读取json数据(Read json data from Android with php)
我正在尝试使用php服务器从Android的反编译应用程序中读取数据。 我使用
wireshark
来了解应用程序发送的数据类型,结果是:{“initType”:“第一次”,“参数”:true,“details”:................}
我试图捕获这些数据并将其插入到具有此PHP代码的文件中:
<?php $json = $_POST["initType"]; $decoded = json_decode($json, TRUE); if ($decoded === FALSE) { throw new Exception('Bad JSON format.'); } $file_handle = fopen('tmp.json', 'w'); fwrite($file_handle, $decoded); fclose($file_handle); ?>
该文件已正确生成但它是空的。 错误是什么?
I'm trying to read data from a decompiled application of Android with a php server. I used
wireshark
to understand what types of data the application sends, and the result is:{"initType":"first time","parameters":true,"details":................}
I trying to capture this data and insert them in a file with this php code:
<?php $json = $_POST["initType"]; $decoded = json_decode($json, TRUE); if ($decoded === FALSE) { throw new Exception('Bad JSON format.'); } $file_handle = fopen('tmp.json', 'w'); fwrite($file_handle, $decoded); fclose($file_handle); ?>
The file is correctly generated but it's empty. What is the error?
原文:https://stackoverflow.com/questions/14143121
最满意答案
这是一个C#集合初始化程序。 你基本上调用Add()两次。 您实际创建的对象取决于ID类。 ID类必须实现ICollection接口才能使此代码正常工作。
var me = new List<string>() { {"some string"}, { "string"} };
This is a C# collection initializer. You essentially called Add() twice. What object you have actually created depends on ID class. ID class must implement ICollection interface for this code to work.
var me = new List<string>() { {"some string"}, { "string"} };
相关问答
更多-
您需要覆盖类中的toSting()方法: public class Tuple { public String toString() { return "name=" + name + ", phone=" +phone' } ... 你看到的是java.lang.Object中“toString()”的默认实现,它只是输出有关对象本身的信息。 通过重写此方法,您可以提供对您更有意义的对象表示。 我上面发布的只是一个建议。 You need to override ...
-
这是一个C#集合初始化程序。 你基本上调用Add()两次。 您实际创建的对象取决于ID类。 ID类必须实现ICollection接口才能使此代码正常工作。 var me = new List
() { {"some string"}, { "string"} }; This is a C# collection initializer. You essentially called Add() twice. What object you have actually created depe ... -
new PostpaidProfile()创建了一个新的类实例。 default(AutoliftResult)为指定的类型创建默认值。 对于引用类型,它为null 。 对于值类型,通常为类型转换为0 - 即如果type为int ,则默认值为0 ; 如果type是bool ,则默认值为false等。 new PostpaidProfile() creates a new instance of the class. default(AutoliftResult) creates a default valu ...
-
不要将方法本身作为泛型,而应该使整个基类成为泛型。 例如: public abstract class ObjectManager
where T : ObjectBase { protected abstract bool Update(T obj); } 每个具体的ObjectManager应该继承它管理的类型的ObjectManager ,如下所示: public class ConsumerManager : ObjectManager { protect ... -
C#中的泛型 - 无法将'classname'转换为'TGenericClass'(Generics in C# - Cannot convert 'classname' to 'TGenericClass')[2023-07-28]
为什么C#编译器在使用接口时允许进行强制转换,但是当我使用实现相同接口的类时,它无法计算出类型? 好问题。 考虑以下: public interface I {} public class D {} // Note that D does not even implement I! public class E { public static M(T t) { D d1 = (D)t; // Illegal D d2 = (D)(object)t; // ... -
在C#中传递变量(Passing variables in C#)[2023-05-25]
这是一个范围问题。 你在你的方法中声明了tb ,所以在方法之外它不存在。 你想在类本身的方法之外声明tb : TextBox tb; public Form1() { InitializeComponent(); } public void Form1_Load(object sender, EventArgs e) { tb = new TextBox(); tb.Dock = System.Windows.Forms.DockStyle.Fill; tb.Locat ... -
你可以像这样制作一个静态通用助手方法: public static class FormHelper { public static TForm ShowAndActivate
(TForm form) where TForm : Form, new() { if (form == null || form.IsDisposed) { form = new TForm(); form.Show(); ... -
如果XPath不起作用,你可以写这样的东西: public IWebElement GetElements(params By[] searchBy) { var list = new List
(); foreach (var by in searchBy) { list.AddRange(driver.FindElements(by)); } return list.Count == 1 ? li ... -
您将在循环的每次迭代中覆盖文本值。 更新的代码: private void button5_Click(object sender, EventArgs e) { HtmlElementCollection links = webBrowser1.Document.GetElementsByTagName("input"); foreach (HtmlElement link in links) { if (link.GetAttribute("className" ...
-
既然你的静态方法正在创建它的类的实例,我建议采用不同的方法: 创建一个包含ParseLine所有类都可以实现的接口。 (更改正确的返回类型): public interface IParseLine { string ParseLine(string line); } 让所有包含ParseLine()的类实现IParseLine 。 创建类的实例,将其IParseLine转换为IParseLine ,然后执行以下方法: IParseLine pl = Activator.CreateInstanc ...