我有一些值存储在变量$a中$b,$c.现在我要将这些值加载到新文件中(创建文件和加载).我是Perl的新手,我该怎么办?
我在PHP循环中填充多个表单,并将它们与<form id='X'>
它们区分开来.它们在HTML中看起来像这样:
<form id='34' class='customer_contact' name='customercontact' method='post' action='customerUpdate.php'>
Förnamn: <br /><input type='text' name='contact_firstname' class='textbox' value='text....'>
Efternamn: <br /><input type='text' name='contact_lastname' class='textbox' value='text....'>
Telefonnummer: <br /><input type='text' name='contact_phone' class='textbox' value='text....'>
Mobiltelefon: <br /><input type='text' name='contact_cellphone' class='textbox' value='text....'>
E-mail: <br /><input type='text' name='contact_email' class='textbox' value='text....'>
<select name='isActive'>
<option value="0" selected>Inaktiv</option>
<option value="1">Aktiv</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码序列化它们:
<script type="text/javascript">
$(document).ready(function() {
$('#customer_contact_save').live('click', function(e){
e.preventDefault();
$.each($('form.customer_contact'), function(index) {
var sData = $(this).serialize();
$.ajax({
type: "POST",
url: "updateCustomer.php",
data: sData,
success: function(someMessageFromPhp) {
alert(someMessageFromPhp); …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
public class PuntoMappa
{
string Lat;
string Lng;
public PuntoMappa(string Lat, string Lng)
{
this.Lat = Lat;
this.Lng = Lng;
}
}
PuntiCategoriaMappa.Add("1111", new PuntoMappa("1", "2"));
PuntiCategoriaMappa.Add("2222", new PuntoMappa("3", "4"));
PuntiCategoriaMappa.Add("3333", new PuntoMappa("5", "6"));
var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PuntiCategoriaMappa", "PuntiCategoriaMappa = " + jsonSerializer.Serialize(PuntiCategoriaMappa) + ";", true);
Run Code Online (Sandbox Code Playgroud)
但序列化是:
PuntiCategoriaMappa = {"1111":{},"2222":{},"3333":{}};
Run Code Online (Sandbox Code Playgroud)
好吧,我丢失了PuntoMappa对象的序列化.
我怎样才能正确地做到这一点?
也许这是有史以来最愚蠢的问题,但不知怎的,我无法自己解决这个问题.我有一个对象(javascript对象),我想使用jQuery ajax传递给我的PHP脚本.当我尝试传入对象时,因为它引发了错误,这可能是因为对象不能按原样传递但必须被序列化.
我已经试过几件事情像$(ui.item).serialize()或者ui.item.serialize()直接把它传递给PHP脚本ui.item.但这不起作用.
这是(子)代码.有关如何序列化/传递对象ui.item到我的脚本的任何建议?
select: function(event, ui){
$(this).autocomplete('close');
$(this).val(ui.item.value);
$.ajax({
url: ABS_BASE + 'ajax/ajax-search-set-location.php',
data: ui.item,
dataType: 'json',
type: 'POST',
success: function(result){ alert(result); return false; }
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用URLScheme,我需要将应用程序A中的序列化NSDictionary发送到我的应用程序B.
在应用程序A中,我使用NSKeyedArchiver将我的NSDictionary序列化为NSData
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"This is value 1", @"key1",
@"value 2", @"key2",
@"value3", @"key3",
@"", @"key4",
@"value5", @"key5",
@"value 6", @"key6",
nil];
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:myDictionary];
[archiver finishEncoding];
[archiver release];
NSString *bytes = [[[NSString alloc] initWithData:data
encoding:NSASCIIStringEncoding] autorelease];
Run Code Online (Sandbox Code Playgroud)
在应用程序B中,我使用的是NSKeyedUnarchiver
NSData *data = [[NSString stringWithFormat:@"%@", val] dataUsingEncoding:NSASCIIStringEncoding];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *myDictionary = [[unarchiver decodeObject] retain];
[unarchiver finishDecoding];
[unarchiver release];
Run Code Online (Sandbox Code Playgroud)
我的序列化NSDictionary看起来像:
bplist00Ô01T$ …
我有一个视图$all_set上的数组,其中包含一些ids.now我想在控制器中使用表单submit.for传递此数组,我使用j子编码和解码.
在我看来:
<?php $all_set=json_encode($all_set); ?>
<input type="hidden" name="all_set" value="<?php echo serialize($all_set); ?>">
Run Code Online (Sandbox Code Playgroud)
上面的值包含(正如我在页面源中看到的):
<input type="hidden" name="all_set" value="s:26:"{"0":"1","5":"2","13":"3"}";">
Run Code Online (Sandbox Code Playgroud)
现在在控制器上:
$result=$this->input->post('all_set');
$result= unserialize($result);
$result=json_decode($result);
print_r($result); die;
Run Code Online (Sandbox Code Playgroud)
这给了我错误,我没有在控制器上获得任何数组.错误:
Message: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes
Run Code Online (Sandbox Code Playgroud)
为什么会这样?请帮忙.
我正在编写简单的客户端 - 服务器应用程序,但我有这个愚蠢的问题(它简化了示例(当我不使用java序列化时一切正常)):
ServerSocket serversocket=null;
Socket socket=null;
String slowo=null;
try {
serversocket=new ServerSocket(8877);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socket=serversocket.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
slowo=(String)ois.readObject();
Run Code Online (Sandbox Code Playgroud)
我的编译器显示:
Serwer.java:51: cannot …Run Code Online (Sandbox Code Playgroud) 在我们公司,我们用Java编写一个简单的序列化器/解串器.有谁知道序列化null值的最佳方法是什么?
我正面临这个问题
class person
{
;
}
person p = new person();
XmlSerializer ser = new XmlSerializer(p.GetType());
FileStream fs = File.Open("sam.xml",FileMode.OpenOrCreate, FileAccess.Write);
ser.Serialize(fs,p)
fs.flush();
fs.close();
FileStream stream = FileStream("sam.xml", FileMode.Open);
XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(stream,new XmlDictionaryReaderQuotas());
Run Code Online (Sandbox Code Playgroud)
现在我的问题是如何在不创建xml文件的情况下创建xdr对象.
我有这门课
public class wordObject implements java.io.Serializable
{
String wordName;
int occCount;
int count;
HashMap<Integer, Double> lineDict;
int[] mat;
public wordObject(String name,int num)
{
wordName = name;
occCount=1;
count = num;
lineDict=new HashMap<Integer,Double>(lineC);
mat = new int[lineC];
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用下面给出的一段代码将类的实例写入磁盘时
public static writeObj(WordObject obj)
FileOutputStream f_out = new FileOutputStream(loc);
// Write object with ObjectOutputStream
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
// Write object out to disk,obj is instance of wordObject
obj_out.writeObject ( obj );
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Exception in thread "main" java.io.NotSerializableException: searchTAemd …Run Code Online (Sandbox Code Playgroud) serialization ×10
java ×3
c# ×2
jquery ×2
json ×2
codeigniter ×1
dictionary ×1
filestream ×1
ios ×1
javascript ×1
nsdata ×1
nsdictionary ×1
perl ×1
perl-io ×1
php ×1
post ×1
xml ×1