我正在尝试创建两个方法来使用序列化/反序列化类Json.Net并将它们保存/加载到文件中,这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
namespace System
{
public static class SystemExtentions
{
public static void SaveToFile(this object data, string FileName)
{
using (StreamWriter writer = new StreamWriter(FileName))
{
string s = JsonConvert.SerializeObject(data);
writer.Write(s);
writer.Close();
}
}
public static void LoadFromFile<t>(t date,string FileName)
{
using (StreamReader reader = new StreamReader(FileName))
{
data = JsonConvert.DeserializeObject<t>(reader.ReadToEnd());
reader.Close();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但在LoadFromFile方法data = JsonConvert.DeserializeObject<t>(reader.ReadToEnd());不起作用!这意味着如果我有这个代码: …
如果生成HTML字符串Like
ViewBag.FinalHTML="<a href=\"http://stackoverflow.com\">StackOverFlow</a>";
Run Code Online (Sandbox Code Playgroud)
然后尝试使用以下代码在View中显示它:
This is the best Q&A for programming questions: @ViewBag.FinalHTML
Run Code Online (Sandbox Code Playgroud)
然后结果将是这样的:
This is the best Q&A for programming questions: <a href="http://stackoverflow.com">StackOverFlow</a>
Run Code Online (Sandbox Code Playgroud)
(我知道我怎么能这样做.我有另一个问题!)
ASP.Net MVC是如何做到的?
我使用此代码加载数据并将它们转换为我使用泛型方法获取它的类型:
public List<TResult> LoadFromeStreamFile<TResult>(string Location)
{
List<TResult> result = new List<TResult>();
StreamReader reader = new StreamReader(Location);
while (!reader.EndOfStream)
{
result.Add((TResult)reader.ReadLine());
}
reader.Close();
return result;
}
Run Code Online (Sandbox Code Playgroud)
但我在这段代码中有错误result.Add((TResult)reader.ReadLine());
如何投射string到TResult?
我有这个代码来格式化一个字符串
string s = "the first number is: {0} and the last is: {1} ";
int first = 2, last = 5;
string f = String.Format(s, first, last);
Run Code Online (Sandbox Code Playgroud)
我想提取first,并last从最终的格式化字符串(f).它意味着我要脱格式f提取first和last(我的格式为基础(s)).
有一种方式是这样的:
string.Split()(艰难和坏的方式)提取它们但我认为.Net中有一个简单的解决方案,但我不知道这是什么.
任何人都可以告诉我简单的方法是什么?
这是wordpress主题的index.php的php代码:
<section id="content">
<?php
$i=1;
while(have_posts() && i < 7):the_post();
$tumbUrl = '';
if(has_post_thumbnail())
{
$tumbUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
}
if(i < 4):
?>
<div id="row1">
<div id="tile<?echo $i?>" class="tile">
<div id="img<?echo $i?>" class="tileimage"<?if($tumbUrl != ''):?> style="background-image:<?echo $tumbUrl; ?>"<?endif;?>></div>
<div id="text<?echo $i?>" class="tiletext"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
</div>
</div>
<?
else:
?>
<div id="row2">
<div id="tile<?echo $i?>" class="tile">
<div id="img<?echo $i?>" class="tileimage"<?if($tumbUrl != ''):?> style="background-image:<?echo $tumbUrl; ?>"<?endif;?>></div>
<div id="text<?echo $i?>" class="tiletext"><a href="<?php the_permalink() ?>" …Run Code Online (Sandbox Code Playgroud) 我想计算从现在到另一个日期时间的秒数,例如明天上午8:00.我找不到任何东西(或者我没有使用好的关键词 - 我不知道另一个!)
有谁能够帮我?